Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542
This commit is contained in:
parent
3b2511d96d
commit
81ccda77eb
2155 changed files with 54307 additions and 46870 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
|
@ -0,0 +1,9 @@
|
|||
name: 'Configuration override integration test'
|
||||
type: module
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
|
||||
dependencies:
|
||||
- block
|
||||
- block_test
|
|
@ -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 }
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
|
@ -3,3 +3,7 @@ type: module
|
|||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
|
||||
dependencies:
|
||||
- block
|
||||
- block_content
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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']);
|
||||
}
|
||||
|
||||
}
|
|
@ -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().
|
||||
*/
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue