Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663
This commit is contained in:
parent
eb34d130a8
commit
f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions
|
@ -43,11 +43,19 @@ class Context extends ComponentContext implements ContextInterface {
|
|||
protected $cacheabilityMetadata;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Create a context object.
|
||||
*
|
||||
* @param \Drupal\Core\Plugin\Context\ContextDefinitionInterface $context_definition
|
||||
* The context definition.
|
||||
* @param mixed $context_value|NULL
|
||||
* The context value object.
|
||||
*/
|
||||
public function __construct(ContextDefinitionInterface $context_definition) {
|
||||
parent::__construct($context_definition);
|
||||
public function __construct(ContextDefinitionInterface $context_definition, $context_value = NULL) {
|
||||
parent::__construct($context_definition, NULL);
|
||||
$this->cacheabilityMetadata = new CacheableMetadata();
|
||||
if (!is_null($context_value)) {
|
||||
$this->setContextValue($context_value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,19 +88,22 @@ class Context extends ComponentContext implements ContextInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Sets the context value.
|
||||
*
|
||||
* @param mixed $value
|
||||
* The value of this context, matching the context definition.
|
||||
*/
|
||||
public function setContextValue($value) {
|
||||
protected function setContextValue($value) {
|
||||
// Add the value as a cacheable dependency only if implements the interface
|
||||
// to prevent it from disabling caching with a max-age 0.
|
||||
if ($value instanceof CacheableDependencyInterface) {
|
||||
$this->addCacheableDependency($value);
|
||||
}
|
||||
if ($value instanceof TypedDataInterface) {
|
||||
return $this->setContextData($value);
|
||||
$this->contextData = $value;
|
||||
}
|
||||
else {
|
||||
return $this->setContextData($this->getTypedDataManager()->create($this->contextDefinition->getDataDefinition(), $value));
|
||||
$this->contextData = $this->getTypedDataManager()->create($this->contextDefinition->getDataDefinition(), $value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,13 +130,6 @@ class Context extends ComponentContext implements ContextInterface {
|
|||
return $this->contextData;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setContextData(TypedDataInterface $data) {
|
||||
$this->contextData = $data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -170,4 +174,16 @@ class Context extends ComponentContext implements ContextInterface {
|
|||
return $this->cacheabilityMetadata->getCacheMaxAge();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function createFromContext(ContextInterface $old_context, $value) {
|
||||
$context = new static($old_context->getContextDefinition(), $value);
|
||||
$context->addCacheableDependency($old_context);
|
||||
if (method_exists($old_context, 'getTypedDataManager')) {
|
||||
$context->setTypedDataManager($old_context->getTypedDataManager());
|
||||
}
|
||||
return $context;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -72,6 +72,7 @@ class ContextHandler implements ContextHandlerInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function applyContextMapping(ContextAwarePluginInterface $plugin, $contexts, $mappings = array()) {
|
||||
/** @var $contexts \Drupal\Core\Plugin\Context\ContextInterface[] */
|
||||
$mappings += $plugin->getContextMapping();
|
||||
// Loop through each of the expected contexts.
|
||||
|
||||
|
@ -94,7 +95,7 @@ class ContextHandler implements ContextHandlerInterface {
|
|||
|
||||
// Pass the value to the plugin if there is one.
|
||||
if ($contexts[$context_id]->hasContextValue()) {
|
||||
$plugin->setContextValue($plugin_context_id, $contexts[$context_id]->getContextValue());
|
||||
$plugin->setContextValue($plugin_context_id, $contexts[$context_id]->getContextData());
|
||||
}
|
||||
elseif ($plugin_context_definition->isRequired()) {
|
||||
// Collect required contexts that exist but are missing a value.
|
||||
|
|
|
@ -68,7 +68,7 @@ interface ContextHandlerInterface {
|
|||
*
|
||||
* @param \Drupal\Core\Plugin\ContextAwarePluginInterface $plugin
|
||||
* A plugin about to be evaluated.
|
||||
* @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
|
||||
* @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
|
||||
* An array of contexts to set on the plugin. They will only be set if they
|
||||
* match the plugin's context definitions.
|
||||
* @param array $mappings
|
||||
|
|
|
@ -9,13 +9,19 @@ namespace Drupal\Core\Plugin\Context;
|
|||
|
||||
use Drupal\Component\Plugin\Context\ContextInterface as ComponentContextInterface;
|
||||
use Drupal\Core\Cache\CacheableDependencyInterface;
|
||||
use Drupal\Core\TypedData\TypedDataInterface;
|
||||
|
||||
/**
|
||||
* Interface for context.
|
||||
*/
|
||||
interface ContextInterface extends ComponentContextInterface, CacheableDependencyInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return \Drupal\Core\Plugin\Context\ContextDefinitionInterface
|
||||
*/
|
||||
public function getContextDefinition();
|
||||
|
||||
/**
|
||||
* Gets the context value as typed data object.
|
||||
*
|
||||
|
@ -23,16 +29,6 @@ interface ContextInterface extends ComponentContextInterface, CacheableDependenc
|
|||
*/
|
||||
public function getContextData();
|
||||
|
||||
/**
|
||||
* Sets the context value as typed data object.
|
||||
*
|
||||
* @param \Drupal\Core\TypedData\TypedDataInterface $data
|
||||
* The context value as a typed data object.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setContextData(TypedDataInterface $data);
|
||||
|
||||
/**
|
||||
* Adds a dependency on an object: merges its cacheability metadata.
|
||||
*
|
||||
|
@ -51,4 +47,17 @@ interface ContextInterface extends ComponentContextInterface, CacheableDependenc
|
|||
*/
|
||||
public function addCacheableDependency($dependency);
|
||||
|
||||
/**
|
||||
* Creates a new context with a different value.
|
||||
*
|
||||
* @param \Drupal\Core\Plugin\Context\ContextInterface $old_context
|
||||
* The context object used to create a new object. Cacheability metadata
|
||||
* will be copied over.
|
||||
* @param mixed $value
|
||||
* The value of the new context object.
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function createFromContext(ContextInterface $old_context, $value);
|
||||
|
||||
}
|
||||
|
|
|
@ -32,8 +32,7 @@ interface ContextProviderInterface {
|
|||
* $node = ...
|
||||
*
|
||||
* // Set that specific node as the value of the 'node' context.
|
||||
* $context = new Context(new ContextDefinition('entity:node'));
|
||||
* $context->setContextValue($node);
|
||||
* $context = new Context(new ContextDefinition('entity:node'), $node);
|
||||
* return ['node' => $context];
|
||||
* @endcode
|
||||
*
|
||||
|
|
|
@ -56,11 +56,12 @@ trait ContextAwarePluginAssignmentTrait {
|
|||
if (count($options) > 1) {
|
||||
$assignments = $plugin->getContextMapping();
|
||||
$element[$context_slot] = [
|
||||
'#title' => $this->t('Select a @context value:', ['@context' => $context_slot]),
|
||||
'#title' => $definition->getLabel() ?: $this->t('Select a @context value:', ['@context' => $context_slot]),
|
||||
'#type' => 'select',
|
||||
'#options' => $options,
|
||||
'#required' => $definition->isRequired(),
|
||||
'#default_value' => !empty($assignments[$context_slot]) ? $assignments[$context_slot] : '',
|
||||
'#description' => $definition->getDescription(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,25 @@ abstract class ContextAwarePluginBase extends ComponentContextAwarePluginBase im
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return \Drupal\Core\Plugin\Context\ContextInterface[]
|
||||
*/
|
||||
protected function createContextFromConfiguration(array $context_configuration) {
|
||||
// This method is overridden so that it will use
|
||||
// \Drupal\Core\Plugin\Context\Context instead.
|
||||
$contexts = [];
|
||||
foreach ($context_configuration as $key => $value) {
|
||||
$context_definition = $this->getContextDefinition($key);
|
||||
$contexts[$key] = new Context($context_definition, $value);
|
||||
}
|
||||
return $contexts;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return \Drupal\Core\Plugin\Context\ContextInterface
|
||||
* The context object.
|
||||
*
|
||||
* This code is identical to the Component in order to pick up a different
|
||||
* Context class.
|
||||
*/
|
||||
|
@ -52,6 +71,14 @@ abstract class ContextAwarePluginBase extends ComponentContextAwarePluginBase im
|
|||
parent::setContext($name, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setContextValue($name, $value) {
|
||||
$this->context[$name] = Context::createFromContext($this->getContext($name), $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -84,6 +111,15 @@ abstract class ContextAwarePluginBase extends ComponentContextAwarePluginBase im
|
|||
return parent::getContextDefinitions();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return \Drupal\Core\Plugin\Context\ContextDefinitionInterface
|
||||
*/
|
||||
public function getContextDefinition($name) {
|
||||
return parent::getContextDefinition($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the context handler.
|
||||
*
|
||||
|
|
|
@ -154,7 +154,7 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInt
|
|||
* definitions should be cleared along with other, related cache entries.
|
||||
*/
|
||||
public function setCacheBackend(CacheBackendInterface $cache_backend, $cache_key, array $cache_tags = array()) {
|
||||
Cache::validateTags($cache_tags);
|
||||
assert('\Drupal\Component\Assertion\Inspector::assertAllStrings($cache_tags)', 'Cache Tags must be strings.');
|
||||
$this->cacheBackend = $cache_backend;
|
||||
$this->cacheKey = $cache_key;
|
||||
$this->cacheTags = $cache_tags;
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Drupal\Core\Plugin\Discovery;
|
|||
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
|
||||
use Drupal\Component\Discovery\YamlDiscovery as ComponentYamlDiscovery;
|
||||
use Drupal\Component\Plugin\Discovery\DiscoveryTrait;
|
||||
use Drupal\Core\StringTranslation\TranslationWrapper;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
|
||||
/**
|
||||
* Allows YAML files to define plugin definitions.
|
||||
|
@ -18,7 +18,7 @@ use Drupal\Core\StringTranslation\TranslationWrapper;
|
|||
* If the value of a key (like title) in the definition is translatable then
|
||||
* the addTranslatableProperty() method can be used to mark it as such and also
|
||||
* to add translation context. Then
|
||||
* \Drupal\Core\StringTranslation\TranslationWrapper will be used to translate
|
||||
* \Drupal\Core\StringTranslation\TranslatableMarkup will be used to translate
|
||||
* the string and also to mark it safe. Only strings written in the YAML files
|
||||
* should be marked as safe, strings coming from dynamic plugin definitions
|
||||
* potentially containing user input should not.
|
||||
|
@ -83,7 +83,7 @@ class YamlDiscovery implements DiscoveryInterface {
|
|||
$definitions = array();
|
||||
foreach ($plugins as $provider => $list) {
|
||||
foreach ($list as $id => $definition) {
|
||||
// Add translation wrappers.
|
||||
// Add TranslatableMarkup.
|
||||
foreach ($this->translatableProperties as $property => $context_key) {
|
||||
if (isset($definition[$property])) {
|
||||
$options = [];
|
||||
|
@ -93,7 +93,7 @@ class YamlDiscovery implements DiscoveryInterface {
|
|||
$options['context'] = $definition[$context_key];
|
||||
unset($definition[$context_key]);
|
||||
}
|
||||
$definition[$property] = new TranslationWrapper($definition[$property], [], $options);
|
||||
$definition[$property] = new TranslatableMarkup($definition[$property], [], $options);
|
||||
}
|
||||
}
|
||||
// Add ID and provider.
|
||||
|
|
Reference in a new issue