reverted: --- b/core/modules/block/src/EventSubscriber/CurrentLanguageContext.php +++ a/core/modules/block/src/EventSubscriber/CurrentLanguageContext.php @@ -13,8 +13,6 @@ use Drupal\Core\Plugin\Context\Context; use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\TypedData\DataDefinition; -use Drupal\Core\TypedData\Plugin\DataType\Language; /** * Sets the current language as a context. @@ -49,9 +47,8 @@ $info = $this->languageManager->getDefinedLanguageTypesInfo(); foreach ($language_types as $type_key) { if (isset($info[$type_key]['name'])) { + $context = new Context(new ContextDefinition('language', $info[$type_key]['name'])); + $context->setContextValue($this->languageManager->getCurrentLanguage($type_key)); - $context_value = Language::createInstance(DataDefinition::createFromDataType('language')); - $context_value->setValue($this->languageManager->getCurrentLanguage($type_key)); - $context = new Context(new ContextDefinition('language', $info[$type_key]['name']), $context_value); $cacheability = new CacheableMetadata(); $cacheability->setCacheContexts(['languages:' . $type_key]); reverted: --- b/core/modules/block/src/EventSubscriber/CurrentUserContext.php +++ a/core/modules/block/src/EventSubscriber/CurrentUserContext.php @@ -10,7 +10,6 @@ use Drupal\block\Event\BlockContextEvent; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Entity\Plugin\DataType\EntityAdapter; use Drupal\Core\Plugin\Context\Context; use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Session\AccountInterface; @@ -56,7 +55,8 @@ public function onBlockActiveContext(BlockContextEvent $event) { $current_user = $this->userStorage->load($this->account->id()); + $context = new Context(new ContextDefinition('entity:user', $this->t('Current user'))); + $context->setContextValue($current_user); - $context = new Context(new ContextDefinition('entity:user', $this->t('Current user')), EntityAdapter::createFromEntity($current_user)); $cacheability = new CacheableMetadata(); $cacheability->setCacheContexts(['user']); $context->addCacheableDependency($cacheability); reverted: --- b/core/modules/block/src/EventSubscriber/NodeRouteContext.php +++ a/core/modules/block/src/EventSubscriber/NodeRouteContext.php @@ -8,7 +8,6 @@ namespace Drupal\block\EventSubscriber; use Drupal\block\Event\BlockContextEvent; -use Drupal\Core\Entity\Plugin\DataType\EntityAdapter; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Plugin\Context\Context; use Drupal\Core\Plugin\Context\ContextDefinition; @@ -44,14 +43,13 @@ $context = new Context(new ContextDefinition('entity:node', NULL, FALSE)); if (($route_object = $this->routeMatch->getRouteObject()) && ($route_contexts = $route_object->getOption('parameters')) && isset($route_contexts['node'])) { if ($node = $this->routeMatch->getParameter('node')) { + $context->setContextValue($node); - $context = new Context(new ContextDefinition($route_contexts['node']['type']), EntityAdapter::createFromEntity($node)); - $event->setContext('node.node', $context); } + $event->setContext('node.node', $context); } elseif ($this->routeMatch->getRouteName() == 'node.add') { $node_type = $this->routeMatch->getParameter('node_type'); + $context->setContextValue(Node::create(array('type' => $node_type->id()))); - $context = new Context(new ContextDefinition('entity:node'), EntityAdapter::createFromEntity(Node::create(array('type' => $node_type->id())))); - $event->setContext('node.node', $context); } $cacheability = new CacheableMetadata(); $cacheability->setCacheContexts(['route']); only in patch2: unchanged: --- a/core/modules/language/src/ContextProvider/CurrentLanguageContext.php +++ b/core/modules/language/src/ContextProvider/CurrentLanguageContext.php @@ -13,6 +13,8 @@ use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Plugin\Context\ContextProviderInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\Core\TypedData\DataDefinition; +use Drupal\Core\TypedData\Plugin\DataType\Language; /** * Sets the current language as a context. @@ -57,8 +59,9 @@ public function getRuntimeContexts(array $unqualified_context_ids) { $result = []; foreach ($language_types as $type_key) { if (isset($info[$type_key]['name'])) { - $context = new Context(new ContextDefinition('language', $info[$type_key]['name'])); - $context->setContextValue($this->languageManager->getCurrentLanguage($type_key)); + $context_value = Language::createInstance(DataDefinition::createFromDataType('language')); + $context_value->setValue($this->languageManager->getCurrentLanguage($type_key)); + $context = new Context(new ContextDefinition('language', $info[$type_key]['name']), $context_value); $cacheability = new CacheableMetadata(); $cacheability->setCacheContexts(['languages:' . $type_key]); only in patch2: unchanged: --- a/core/modules/node/src/ContextProvider/NodeRouteContext.php +++ b/core/modules/node/src/ContextProvider/NodeRouteContext.php @@ -2,22 +2,22 @@ /** * @file - * Contains \Drupal\node\ContextProvider\NodeRouteContext. + * Contains \Drupal\block\EventSubscriber\NodeRouteContext. */ -namespace Drupal\node\ContextProvider; +namespace Drupal\block\EventSubscriber; +use Drupal\block\Event\BlockContextEvent; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Plugin\Context\Context; use Drupal\Core\Plugin\Context\ContextDefinition; -use Drupal\Core\Plugin\Context\ContextProviderInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\node\Entity\Node; /** * Sets the current node as a context on node routes. */ -class NodeRouteContext implements ContextProviderInterface { +class NodeRouteContext extends BlockContextSubscriberBase { /** * The route match object. @@ -39,13 +39,13 @@ public function __construct(RouteMatchInterface $route_match) { /** * {@inheritdoc} */ - public function getRuntimeContexts(array $unqualified_context_ids) { - $result = []; + public function onBlockActiveContext(BlockContextEvent $event) { $context = new Context(new ContextDefinition('entity:node', NULL, FALSE)); if (($route_object = $this->routeMatch->getRouteObject()) && ($route_contexts = $route_object->getOption('parameters')) && isset($route_contexts['node'])) { if ($node = $this->routeMatch->getParameter('node')) { $context->setContextValue($node); } + $event->setContext('node.node', $context); } elseif ($this->routeMatch->getRouteName() == 'node.add') { $node_type = $this->routeMatch->getParameter('node_type'); @@ -54,17 +54,15 @@ public function getRuntimeContexts(array $unqualified_context_ids) { $cacheability = new CacheableMetadata(); $cacheability->setCacheContexts(['route']); $context->addCacheableDependency($cacheability); - $result['node'] = $context; - - return $result; + $event->setContext('node.node', $context); } /** * {@inheritdoc} */ - public function getAvailableContexts() { + public function onBlockAdministrativeContext(BlockContextEvent $event) { $context = new Context(new ContextDefinition('entity:node')); - return ['node' => $context]; + $event->setContext('node.node', $context); } } only in patch2: unchanged: --- a/core/modules/user/src/ContextProvider/CurrentUserContext.php +++ b/core/modules/user/src/ContextProvider/CurrentUserContext.php @@ -9,6 +9,7 @@ use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\Plugin\DataType\EntityAdapter; use Drupal\Core\Plugin\Context\Context; use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Plugin\Context\ContextProviderInterface; @@ -55,8 +56,7 @@ public function __construct(AccountInterface $account, EntityManagerInterface $e public function getRuntimeContexts(array $unqualified_context_ids) { $current_user = $this->userStorage->load($this->account->id()); - $context = new Context(new ContextDefinition('entity:user', $this->t('Current user'))); - $context->setContextValue($current_user); + $context = new Context(new ContextDefinition('entity:user', $this->t('Current user')), EntityAdapter::createFromEntity($current_user)); $cacheability = new CacheableMetadata(); $cacheability->setCacheContexts(['user']); $context->addCacheableDependency($cacheability);