Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542

This commit is contained in:
Pantheon Automation 2015-08-27 12:03:05 -07:00 committed by Greg Anderson
parent 3b2511d96d
commit 81ccda77eb
2155 changed files with 54307 additions and 46870 deletions

View file

@ -1,5 +1,5 @@
config.sync:
title: 'Configuration management'
description: 'Import, export, or synchronize your site configuration.'
title: 'Configuration synchronization'
description: 'Import and export your configuration.'
route_name: config.sync
parent: system.admin_config_development

View file

@ -15,9 +15,20 @@ function config_help($route_name, RouteMatchInterface $route_match) {
case 'help.page.config':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Configuration manager module provides a user interface for importing and exporting configuration changes; i.e., for staging configuration data between multiple instances of this web site. For more information, see the online handbook entry for <a href="!url">Configuration manager module</a>', array(
'!url' => 'https://www.drupal.org/documentation/administer/config',
)) . '</p>';
$output .= '<p>' . t('The Configuration Manager module provides a user interface for importing and exporting configuration changes between installations of your website in different environments. Configuration is stored in YAML format. For more information, see the <a href="!url">online documentation for the Configuration Manager module</a>.', array('!url' => 'https://www.drupal.org/documentation/administer/config')) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Exporting the full configuration') . '</dt>';
$output .= '<dd>' . t('You can create and download an archive consisting of all your site\'s configuration exported as <em>*.yml</em> files on the <a href="!url">Export</a> page.' , array('!url' => \Drupal::url('config.export_full'))) . '</dd>';
$output .= '<dt>' . t('Importing a full configuration') . '</dt>';
$output .= '<dd>' . t('You can upload a full site configuration from an archive file on the <a href="!url">Import</a> page. When importing data from a different environment, the site and import files must have matching configuration values for UUID in the <em>system.site</em> configuration item. That means that your other environments should initially be set up as clones of the target site. Migrations are not supported.', array('!url' => \Drupal::url('config.import_full'))) . '</dd>';
$output .= '<dt>' . t('Synchronizing configuration'). '</dt>';
$output .= '<dd>' . t('You can review differences between the active configuration and an imported configuration archive on the <a href="!synchronize">Synchronize</a> page to ensure that the changes are as expected, before finalizing the import. The Synchronize page also shows configuration items that would be added or removed.', array('!synchronize' => \Drupal::url('config.sync'))) . '</dd>';
$output .= '<dt>' . t('Exporting a single configuration item') . '</dt>';
$output .= '<dd>' . t('You can export a single configuration item by selecting a <em>Configuration type</em> and <em>Configuration name</em> on the <a href="!single-export">Single export</a> page. The configuration and its corresponding <em>*.yml file name</em> are then displayed on the page for you to copy.', array('!single-export' => \Drupal::url('config.export_single'))) . '</dd>';
$output .= '<dt>' . t('Importing a single configuration item') . '</dt>';
$output .= '<dd>' . t('You can import a single configuration item by pasting it in YAML format into the form on the <a href="!single-import">Single import</a> page.', array('!single-import' => \Drupal::url('config.import_single'))) . '</dd>';
$output .= '</dl>';
return $output;
case 'config.sync':
@ -25,9 +36,24 @@ function config_help($route_name, RouteMatchInterface $route_match) {
$output .= '<p>' . t('Import configuration that is placed in your staging directory. All changes, deletions, renames, and additions are listed below.') . '</p>';
return $output;
case 'config.export_full':
$output = '';
$output .= '<p>' . t('The full export page can be used to export the full configuration of this site, and download it as a gzipped tar file.') . '</p>';
return $output;
case 'config.import_full':
$output = '';
$output .= '<p>' . t('After uploading a configuration archive, you will be able to examine the changes and import them.') . '</p>';
$output .= '<p>' . t('The full import page can be used to import a full set of configuration for this site by uploading a gzipped or bzipped tar file consisting of all configuration YAML files. The results will be placed in a the staging directory, so they can be compared in the Synchronize tab. There the import can be finalized.') . '</p>';
return $output;
case 'config.export_single':
$output = '';
$output .= '<p>' . t('The single export page can be used to display a single configuration item in a YAML structure.') . '</p>';
return $output;
case 'config.import_single':
$output = '';
$output .= '<p>' . t('The single import page can be used to import a single configuration item by pasting a YAML structure into the text field.') . '</p>';
return $output;
}
}

View file

@ -0,0 +1,65 @@
<?php
/**
* @file
* Contains \Drupal\config\Tests\CacheabilityMetadataConfigOverrideIntegrationTest.
*/
namespace Drupal\config\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests if configuration overrides correctly affect cacheability metadata.
*
* @group config
*/
class CacheabilityMetadataConfigOverrideIntegrationTest extends WebTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'block_test',
'config_override_integration_test',
];
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
// @todo If our block does not contain any content then the cache context
// is not bubbling up and the test fails. Remove this line once the cache
// contexts are properly set. See https://www.drupal.org/node/2529980.
\Drupal::state()->set('block_test.content', 'Needs to have some content');
$this->drupalLogin($this->drupalCreateUser());
}
/**
* Tests if config overrides correctly set cacheability metadata.
*/
public function testConfigOverride() {
// Check the default (disabled) state of the cache context. The block label
// should not be overridden.
$this->drupalGet('<front>');
$this->assertNoText('Overridden block label');
// Both the cache context and tag should be present.
$this->assertCacheContext('config_override_integration_test');
$this->assertCacheTag('config_override_integration_test_tag');
// Flip the state of the cache context. The block label should now be
// overridden.
\Drupal::state()->set('config_override_integration_test.enabled', TRUE);
$this->drupalGet('<front>');
$this->assertText('Overridden block label');
// Both the cache context and tag should still be present.
$this->assertCacheContext('config_override_integration_test');
$this->assertCacheTag('config_override_integration_test_tag');
}
}

View file

@ -0,0 +1,95 @@
<?php
/**
* @file
* Contains \Drupal\config\Tests\CacheabilityMetadataConfigOverrideTest.
*/
namespace Drupal\config\Tests;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\config_override_test\Cache\PirateDayCacheContext;
use Drupal\simpletest\KernelTestBase;
/**
* Tests if configuration overrides correctly affect cacheability metadata.
*
* @group config
*/
class CacheabilityMetadataConfigOverrideTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'block',
'block_content',
'config',
'config_override_test',
'system',
];
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->installEntitySchema('block_content');
$this->installConfig(['config_override_test']);
}
/**
* Tests if config overrides correctly set cacheability metadata.
*/
public function testConfigOverride() {
// It's pirate day today!
$GLOBALS['it_is_pirate_day'] = TRUE;
$config_factory = $this->container->get('config.factory');
$config = $config_factory->get('system.theme');
// Check that we are using the Pirate theme.
$theme = $config->get('default');
$this->assertEqual('pirate', $theme);
// Check that the cacheability metadata is correct.
$this->assertEqual(['pirate_day'], $config->getCacheContexts());
$this->assertEqual(['config:system.theme', 'pirate-day-tag'], $config->getCacheTags());
$this->assertEqual(PirateDayCacheContext::PIRATE_DAY_MAX_AGE, $config->getCacheMaxAge());
}
/**
* Tests if config overrides set cacheability metadata on config entities.
*/
public function testConfigEntityOverride() {
// It's pirate day today!
$GLOBALS['it_is_pirate_day'] = TRUE;
// Load the User login block and check that its cacheability metadata is
// overridden correctly. This verifies that the metadata is correctly
// applied to config entities.
/** @var EntityManagerInterface $entity_manager */
$entity_manager = $this->container->get('entity.manager');
$block = $entity_manager->getStorage('block')->load('call_to_action');
// Check that our call to action message is appealing to filibusters.
$this->assertEqual($block->label(), 'Draw yer cutlasses!');
// Check that the cacheability metadata is correct.
$this->assertEqual(['pirate_day'], $block->getCacheContexts());
$this->assertEqual(['config:block.block.call_to_action', 'pirate-day-tag'], $block->getCacheTags());
$this->assertEqual(PirateDayCacheContext::PIRATE_DAY_MAX_AGE, $block->getCacheMaxAge());
// Check that duplicating a config entity does not have the original config
// entity's cache tag.
$this->assertEqual(['config:block.block.', 'pirate-day-tag'], $block->createDuplicate()->getCacheTags());
// Check that renaming a config entity does not have the original config
// entity's cache tag.
$block->set('id', 'call_to_looting')->save();
$this->assertEqual(['pirate_day'], $block->getCacheContexts());
$this->assertEqual(['config:block.block.call_to_looting', 'pirate-day-tag'], $block->getCacheTags());
$this->assertEqual(PirateDayCacheContext::PIRATE_DAY_MAX_AGE, $block->getCacheMaxAge());
}
}

View file

@ -31,6 +31,8 @@ class ConfigEntityFormOverrideTest extends WebTestBase {
$overridden_label = 'Overridden label';
$edited_label = 'Edited label';
$config_test_storage = $this->container->get('entity.manager')->getStorage('config_test');
// Set up an override.
$settings['config']['config_test.dynamic.dotted.default']['label'] = (object) array(
'value' => $overridden_label,
@ -39,7 +41,7 @@ class ConfigEntityFormOverrideTest extends WebTestBase {
$this->writeSettings($settings);
// Test that the overridden label is loaded with the entity.
$this->assertEqual(config_test_load('dotted.default')->label(), $overridden_label);
$this->assertEqual($config_test_storage->load('dotted.default')->label(), $overridden_label);
// Test that the original label on the listing page is intact.
$this->drupalGet('admin/structure/config_test');
@ -67,7 +69,7 @@ class ConfigEntityFormOverrideTest extends WebTestBase {
$this->assertIdentical((string) $elements[0]['value'], $edited_label);
// Test that the overridden label is still loaded with the entity.
$this->assertEqual(config_test_load('dotted.default')->label(), $overridden_label);
$this->assertEqual($config_test_storage->load('dotted.default')->label(), $overridden_label);
}
}

View file

@ -295,8 +295,8 @@ class ConfigImporterTest extends KernelTestBase {
$logs = $this->configImporter->getErrors();
$this->assertEqual(count($logs), 1);
$message = SafeMarkup::format('config_test entity with ID @name already exists', array('@name' => 'secondary'));
$this->assertEqual($logs[0], SafeMarkup::format('Unexpected error during import with operation @op for @name: @message.', array('@op' => 'create', '@name' => $name_primary, '@message' => $message)));
$message = SafeMarkup::format("'config_test' entity with ID '@name' already exists", array('@name' => 'secondary'));
$this->assertEqual($logs[0], SafeMarkup::format('Unexpected error during import with operation @op for @name: !message.', array('@op' => 'create', '@name' => $name_primary, '!message' => $message)));
}
/**

View file

@ -127,7 +127,7 @@ class ConfigInstallWebTest extends WebTestBase {
// will install the config_test module first because it is a dependency of
// config_install_fail_test.
// @see \Drupal\system\Form\ModulesListForm::submitForm()
$this->drupalPostForm('admin/modules', array('modules[Testing][config_test][enable]' => TRUE, 'modules[Testing][config_install_fail_test][enable]' => TRUE), t('Save configuration'));
$this->drupalPostForm('admin/modules', array('modules[Testing][config_test][enable]' => TRUE, 'modules[Testing][config_install_fail_test][enable]' => TRUE), t('Install'));
$this->assertRaw('Unable to install Configuration install fail test, <em class="placeholder">config_test.dynamic.dotted.default</em> already exists in active configuration.');
// Uninstall the config_test module to test the confirm form.
@ -138,7 +138,7 @@ class ConfigInstallWebTest extends WebTestBase {
// The user is shown a confirm form because the config_test module is a
// dependency.
// @see \Drupal\system\Form\ModulesListConfirmForm::submitForm()
$this->drupalPostForm('admin/modules', array('modules[Testing][config_install_fail_test][enable]' => TRUE), t('Save configuration'));
$this->drupalPostForm('admin/modules', array('modules[Testing][config_install_fail_test][enable]' => TRUE), t('Install'));
$this->drupalPostForm(NULL, array(), t('Continue'));
$this->assertRaw('Unable to install Configuration install fail test, <em class="placeholder">config_test.dynamic.dotted.default</em> already exists in active configuration.');
@ -152,7 +152,7 @@ class ConfigInstallWebTest extends WebTestBase {
->set('label', 'Je suis Charlie')
->save();
$this->drupalPostForm('admin/modules', array('modules[Testing][config_install_fail_test][enable]' => TRUE), t('Save configuration'));
$this->drupalPostForm('admin/modules', array('modules[Testing][config_install_fail_test][enable]' => TRUE), t('Install'));
$this->assertRaw('Unable to install Configuration install fail test, <em class="placeholder">config_test.dynamic.dotted.default, language/fr/config_test.dynamic.dotted.default</em> already exist in active configuration.');
// Test installing a theme through the UI that has existing configuration.
@ -183,12 +183,12 @@ class ConfigInstallWebTest extends WebTestBase {
$this->drupalLogin($this->adminUser);
// We need to install separately since config_install_dependency_test does
// not depend on config_test and order is important.
$this->drupalPostForm('admin/modules', array('modules[Testing][config_test][enable]' => TRUE), t('Save configuration'));
$this->drupalPostForm('admin/modules', array('modules[Testing][config_install_dependency_test][enable]' => TRUE), t('Save configuration'));
$this->drupalPostForm('admin/modules', array('modules[Testing][config_test][enable]' => TRUE), t('Install'));
$this->drupalPostForm('admin/modules', array('modules[Testing][config_install_dependency_test][enable]' => TRUE), t('Install'));
$this->assertRaw('Unable to install Config install dependency test, <em class="placeholder">config_test.dynamic.other_module_test_with_dependency</em> has unmet dependencies.');
$this->drupalPostForm('admin/modules', array('modules[Testing][config_other_module_config_test][enable]' => TRUE), t('Save configuration'));
$this->drupalPostForm('admin/modules', array('modules[Testing][config_install_dependency_test][enable]' => TRUE), t('Save configuration'));
$this->drupalPostForm('admin/modules', array('modules[Testing][config_other_module_config_test][enable]' => TRUE), t('Install'));
$this->drupalPostForm('admin/modules', array('modules[Testing][config_install_dependency_test][enable]' => TRUE), t('Install'));
$this->rebuildContainer();
$this->assertTrue(entity_load('config_test', 'other_module_test_with_dependency'), 'The config_test.dynamic.other_module_test_with_dependency configuration has been created during install.');
}

View file

@ -7,6 +7,7 @@
namespace Drupal\config_entity_static_cache_test;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
use Drupal\Core\Config\StorageInterface;
@ -40,4 +41,11 @@ class ConfigOverrider implements ConfigFactoryOverrideInterface {
return NULL;
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata($name) {
return new CacheableMetadata();
}
}

View file

@ -0,0 +1,24 @@
id: config_override_test
theme: classy
weight: 0
status: true
langcode: en
region: content
plugin: test_cache
settings:
label: 'Test HTML block'
provider: block_test
label_display: visible
status: true
info: ''
view_mode: default
dependencies:
module:
- block_test
theme:
- classy
visibility:
request_path:
id: request_path
pages: ''
negate: false

View file

@ -0,0 +1,9 @@
name: 'Configuration override integration test'
type: module
package: Testing
version: VERSION
core: 8.x
dependencies:
- block
- block_test

View file

@ -0,0 +1,9 @@
services:
cache_context.config_override_integration_test:
class: Drupal\config_override_integration_test\Cache\ConfigOverrideIntegrationTestCacheContext
tags:
- { name: cache.context }
config_override_integration_test.config_override:
class: Drupal\config_override_integration_test\CacheabilityMetadataConfigOverride
tags:
- { name: config.factory.override }

View file

@ -0,0 +1,47 @@
<?php
/**
* @file
* Contains \Drupal\config_override_integration_test\Cache\ConfigOverrideIntegrationTestCacheContext.
*/
namespace Drupal\config_override_integration_test\Cache;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\Context\CacheContextInterface;
/**
* A cache context service intended for the config override integration test.
*
* Cache context ID: 'config_override_integration_test'.
*/
class ConfigOverrideIntegrationTestCacheContext implements CacheContextInterface {
/**
* {@inheritdoc}
*/
public static function getLabel() {
return t('Config override integration test');
}
/**
* {@inheritdoc}
*/
public function getContext() {
// Default to the 'disabled' state.
$state = \Drupal::state()->get('config_override_integration_test.enabled', FALSE) ? 'yes' : 'no';
return 'config_override_integration_test.' . $state;
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata() {
// Since this depends on State this can change at any time and is not
// cacheable.
$metadata = new CacheableMetadata();
$metadata->setCacheMaxAge(0);
return $metadata;
}
}

View file

@ -0,0 +1,65 @@
<?php
/**
* @file
* Contains \Drupal\config_override_integration_test\CacheabilityMetadataConfigOverride.
*/
namespace Drupal\config_override_integration_test;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
use Drupal\Core\Config\StorageInterface;
/**
* Test implementation of a config override that provides cacheability metadata.
*/
class CacheabilityMetadataConfigOverride implements ConfigFactoryOverrideInterface {
/**
* {@inheritdoc}
*/
public function loadOverrides($names) {
$overrides = [];
// Override the test block depending on the state set in the test.
$state = \Drupal::state()->get('config_override_integration_test.enabled', FALSE);
if (in_array('block.block.config_override_test', $names) && $state !== FALSE) {
$overrides = $overrides + [
'block.block.config_override_test' => [
'settings' => ['label' => 'Overridden block label'],
],
];
}
return $overrides;
}
/**
* {@inheritdoc}
*/
public function getCacheSuffix() {
return 'config_override_integration_test';
}
/**
* {@inheritdoc}
*/
public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
return NULL;
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata($name) {
$metadata = new CacheableMetadata();
if ($name === 'block.block.config_override_test') {
$metadata
->setCacheContexts(['config_override_integration_test'])
->setCacheTags(['config_override_integration_test_tag']);
}
return $metadata;
}
}

View file

@ -0,0 +1,26 @@
langcode: en
status: true
dependencies:
module:
- block_content
theme:
- classy
id: call_to_action
theme: classy
region: content
weight: null
provider: null
plugin: 'block_content:d7c9d8ba-663f-41b4-8756-86bc55c44653'
settings:
id: 'block_content:d7c9d8ba-663f-41b4-8756-86bc55c44653'
label: 'Shop for cheap now!'
provider: block_content
label_display: visible
status: true
info: ''
view_mode: default
visibility:
request_path:
id: request_path
pages: ''
negate: false

View file

@ -3,3 +3,7 @@ type: module
package: Testing
version: VERSION
core: 8.x
dependencies:
- block
- block_content

View file

@ -1,4 +1,8 @@
services:
cache_context.pirate_day:
class: Drupal\config_override_test\Cache\PirateDayCacheContext
tags:
- { name: cache.context }
config_override_test.overrider:
class: Drupal\config_override_test\ConfigOverrider
tags:
@ -7,3 +11,7 @@ services:
class: Drupal\config_override_test\ConfigOverriderLowPriority
tags:
- { name: config.factory.override, priority: -100 }
config_override_test.pirate_day_cacheability_metadata_override:
class: Drupal\config_override_test\PirateDayCacheabilityMetadataConfigOverride
tags:
- { name: config.factory.override }

View file

@ -0,0 +1,66 @@
<?php
/**
* @file
* Contains \Drupal\config_override_test\Cache\PirateDayCacheContext.
*/
namespace Drupal\config_override_test\Cache;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\Context\CacheContextInterface;
/**
* Defines the PirateDayCacheContext service that allows to cache the booty.
*
* Cache context ID: 'pirate_day'.
*/
class PirateDayCacheContext implements CacheContextInterface {
/**
* The length of Pirate Day. It lasts 24 hours.
*
* This is a simplified test implementation. In a real life Pirate Day module
* this data wouldn't be defined in a constant, but calculated in a static
* method. If it were Pirate Day it should return the number of seconds until
* midnight, and on all other days it should return the number of seconds
* until the start of the next Pirate Day.
*/
const PIRATE_DAY_MAX_AGE = 86400;
/**
* {@inheritdoc}
*/
public static function getLabel() {
return t('Pirate day');
}
/**
* {@inheritdoc}
*/
public function getContext() {
$is_pirate_day = static::isPirateDay() ? 'yarr' : 'nay';
return "pirate_day." . $is_pirate_day;
}
/**
* Returns whether or not it is Pirate Day.
*
* To ease testing this is determined with a global variable rather than using
* the traditional compass and sextant.
*
* @return bool
* Returns TRUE if it is Pirate Day today.
*/
public static function isPirateDay() {
return !empty($GLOBALS['it_is_pirate_day']);
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata() {
return new CacheableMetadata();
}
}

View file

@ -7,6 +7,7 @@
namespace Drupal\config_override_test;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
/**
@ -44,5 +45,11 @@ class ConfigOverrider implements ConfigFactoryOverrideInterface {
return NULL;
}
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata($name) {
return new CacheableMetadata();
}
}

View file

@ -7,6 +7,7 @@
namespace Drupal\config_override_test;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
use Drupal\Core\Config\StorageInterface;
@ -49,5 +50,11 @@ class ConfigOverriderLowPriority implements ConfigFactoryOverrideInterface {
return NULL;
}
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata($name) {
return new CacheableMetadata();
}
}

View file

@ -0,0 +1,82 @@
<?php
/**
* @file
* Contains \Drupal\config_override_test\PirateDayCacheabilityMetadataConfigOverride.
*/
namespace Drupal\config_override_test;
use Drupal\config_override_test\Cache\PirateDayCacheContext;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
use Drupal\Core\Config\StorageInterface;
/**
* Test implementation of a config override that provides cacheability metadata.
*/
class PirateDayCacheabilityMetadataConfigOverride implements ConfigFactoryOverrideInterface {
/**
* {@inheritdoc}
*/
public function loadOverrides($names) {
$overrides = [];
// Override the theme and the 'call_to_action' block on Pirate Day.
if (PirateDayCacheContext::isPirateDay()) {
if (in_array('system.theme', $names)) {
$overrides = $overrides + ['system.theme' => ['default' => 'pirate']];
}
if (in_array('block.block.call_to_action', $names)) {
$overrides = $overrides + [
'block.block.call_to_action' => [
'settings' => ['label' => 'Draw yer cutlasses!'],
],
];
}
}
return $overrides;
}
/**
* {@inheritdoc}
*/
public function getCacheSuffix() {
return 'PirateDayConfigOverrider';
}
/**
* {@inheritdoc}
*/
public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
return NULL;
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata($name) {
$metadata = new CacheableMetadata();
$metadata
->setCacheContexts(['pirate_day'])
->setCacheTags(['pirate-day-tag'])
->setCacheMaxAge(PirateDayCacheContext::PIRATE_DAY_MAX_AGE);
return $metadata;
}
/**
* Returns whether or not our overrides are potentially applicable.
*
* @param string $name
* The name of the config object that is being constructed.
*
* @return bool
* TRUE if the merchant ship will be boarded. FALSE if we drink rum instead.
*/
protected function isCacheabilityMetadataApplicable($name) {
return in_array($name, ['system.theme', 'block.block.call_to_action']);
}
}

View file

@ -10,16 +10,6 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
require_once dirname(__FILE__) . '/config_test.hooks.inc';
/**
* Loads a ConfigTest object.
*
* @param string $id
* The ID of the ConfigTest object to load.
*/
function config_test_load($id) {
return entity_load('config_test', $id);
}
/**
* Implements hook_cache_flush().
*/

View file

@ -8,13 +8,41 @@
namespace Drupal\config_test;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Form controller for the test config edit forms.
*/
class ConfigTestForm extends EntityForm {
/**
* The entity query.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $entityQuery;
/**
* Constructs a new ConfigTestForm.
*
* @param \Drupal\Core\Entity\Query\QueryFactory $entity_query
* The entity query.
*/
public function __construct(QueryFactory $entity_query) {
$this->entityQuery = $entity_query;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.query')
);
}
/**
* {@inheritdoc}
*/
@ -33,7 +61,7 @@ class ConfigTestForm extends EntityForm {
'#default_value' => $entity->id(),
'#required' => TRUE,
'#machine_name' => array(
'exists' => 'config_test_load',
'exists' => [$this, 'exists'],
'replace_pattern' => '[^a-z0-9_.]+',
),
);
@ -142,4 +170,25 @@ class ConfigTestForm extends EntityForm {
$form_state->setRedirectUrl($this->entity->urlInfo('collection'));
}
/**
* Determines if the entity already exists.
*
* @param string|int $entity_id
* The entity ID.
* @param array $element
* The form element.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return bool
* TRUE if the entity exists, FALSE otherwise.
*/
public function exists($entity_id, array $element, FormStateInterface $form_state) {
/** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
$entity = $form_state->getFormObject()->getEntity();
return (bool) $this->entityQuery->get($entity->getEntityTypeId())
->condition($entity->getEntityType()->getKey('id'), $entity_id)
->execute();
}
}