Mercurial > hg > isophonics-drupal-site
comparison core/modules/node/src/ContextProvider/NodeRouteContext.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
2 | 2 |
3 namespace Drupal\node\ContextProvider; | 3 namespace Drupal\node\ContextProvider; |
4 | 4 |
5 use Drupal\Core\Cache\CacheableMetadata; | 5 use Drupal\Core\Cache\CacheableMetadata; |
6 use Drupal\Core\Plugin\Context\Context; | 6 use Drupal\Core\Plugin\Context\Context; |
7 use Drupal\Core\Plugin\Context\ContextDefinition; | |
8 use Drupal\Core\Plugin\Context\ContextProviderInterface; | 7 use Drupal\Core\Plugin\Context\ContextProviderInterface; |
8 use Drupal\Core\Plugin\Context\EntityContext; | |
9 use Drupal\Core\Plugin\Context\EntityContextDefinition; | |
9 use Drupal\Core\Routing\RouteMatchInterface; | 10 use Drupal\Core\Routing\RouteMatchInterface; |
10 use Drupal\node\Entity\Node; | 11 use Drupal\node\Entity\Node; |
11 use Drupal\Core\StringTranslation\StringTranslationTrait; | 12 use Drupal\Core\StringTranslation\StringTranslationTrait; |
12 | 13 |
13 /** | 14 /** |
37 /** | 38 /** |
38 * {@inheritdoc} | 39 * {@inheritdoc} |
39 */ | 40 */ |
40 public function getRuntimeContexts(array $unqualified_context_ids) { | 41 public function getRuntimeContexts(array $unqualified_context_ids) { |
41 $result = []; | 42 $result = []; |
42 $context_definition = new ContextDefinition('entity:node', NULL, FALSE); | 43 $context_definition = EntityContextDefinition::create('node')->setRequired(FALSE); |
43 $value = NULL; | 44 $value = NULL; |
44 if (($route_object = $this->routeMatch->getRouteObject()) && ($route_contexts = $route_object->getOption('parameters')) && isset($route_contexts['node'])) { | 45 if (($route_object = $this->routeMatch->getRouteObject()) && ($route_contexts = $route_object->getOption('parameters')) && isset($route_contexts['node'])) { |
45 if ($node = $this->routeMatch->getParameter('node')) { | 46 if ($node = $this->routeMatch->getParameter('node')) { |
46 $value = $node; | 47 $value = $node; |
47 } | 48 } |
63 | 64 |
64 /** | 65 /** |
65 * {@inheritdoc} | 66 * {@inheritdoc} |
66 */ | 67 */ |
67 public function getAvailableContexts() { | 68 public function getAvailableContexts() { |
68 $context = new Context(new ContextDefinition('entity:node', $this->t('Node from URL'))); | 69 $context = EntityContext::fromEntityTypeId('node', $this->t('Node from URL')); |
69 return ['node' => $context]; | 70 return ['node' => $context]; |
70 } | 71 } |
71 | 72 |
72 } | 73 } |