From 0b165a8278abc729ff0265b407cc9e4a10029967 Mon Sep 17 00:00:00 2001 From: Eli Zoller Date: Wed, 25 Nov 2020 10:58:38 -0700 Subject: [PATCH] replace deprecated context definition method - per https://www.drupal.org/node/2976400 --- src/ContextProvider/FileContextProvider.php | 8 +++----- src/ContextProvider/FileRouteContextProvider.php | 8 +++++--- src/ContextProvider/MediaContextProvider.php | 8 +++----- src/ContextProvider/MediaRouteContextProvider.php | 7 ++++--- src/ContextProvider/NodeContextProvider.php | 8 +++----- src/ContextProvider/TermContextProvider.php | 8 +++----- src/ContextProvider/TermRouteContextProvider.php | 11 ++++++----- 7 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/ContextProvider/FileContextProvider.php b/src/ContextProvider/FileContextProvider.php index 9b6e5cc1..014fd824 100644 --- a/src/ContextProvider/FileContextProvider.php +++ b/src/ContextProvider/FileContextProvider.php @@ -3,9 +3,8 @@ namespace Drupal\islandora\ContextProvider; use Drupal\file\FileInterface; -use Drupal\Core\Plugin\Context\Context; -use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Plugin\Context\ContextProviderInterface; +use Drupal\Core\Plugin\Context\EntityContext; use Drupal\Core\StringTranslation\StringTranslationTrait; /** @@ -36,8 +35,7 @@ class FileContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getRuntimeContexts(array $unqualified_context_ids) { - $context_definition = new ContextDefinition('entity:file', NULL, FALSE); - $context = new Context($context_definition, $this->file); + $context = EntityContext::fromEntity($this->file); return ['@islandora.file_route_context_provider:file' => $context]; } @@ -45,7 +43,7 @@ class FileContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getAvailableContexts() { - $context = new Context(new ContextDefinition('entity:file', $this->t('File from entity hook'))); + $context = EntityContext::fromEntityTypeId('entity:file', $this->t('File from entity hook')); return ['@islandora.file_route_context_provider:file' => $context]; } diff --git a/src/ContextProvider/FileRouteContextProvider.php b/src/ContextProvider/FileRouteContextProvider.php index bd55644f..dc00dafe 100644 --- a/src/ContextProvider/FileRouteContextProvider.php +++ b/src/ContextProvider/FileRouteContextProvider.php @@ -4,8 +4,9 @@ namespace Drupal\islandora\ContextProvider; 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\Plugin\Context\EntityContext; +use Drupal\Core\Plugin\Context\EntityContextDefinition; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -37,7 +38,8 @@ class FileRouteContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getRuntimeContexts(array $unqualified_context_ids) { - $context_definition = new ContextDefinition('entity:file', NULL, FALSE); + $context_definition = EntityContextDefinition::fromEntityTypeId('entity:file')->setLabel(NULL)->setRequired(FALSE); + $value = NULL; // Hack the file out of the route. @@ -64,7 +66,7 @@ class FileRouteContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getAvailableContexts() { - $context = new Context(new ContextDefinition('entity:file', $this->t('File from URL'))); + $context = EntityContext::fromEntityTypeId('entity:file', $this->t('File from URL')); return ['file' => $context]; } diff --git a/src/ContextProvider/MediaContextProvider.php b/src/ContextProvider/MediaContextProvider.php index 33270357..01dbd2ea 100644 --- a/src/ContextProvider/MediaContextProvider.php +++ b/src/ContextProvider/MediaContextProvider.php @@ -3,9 +3,8 @@ namespace Drupal\islandora\ContextProvider; use Drupal\media\MediaInterface; -use Drupal\Core\Plugin\Context\Context; -use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Plugin\Context\ContextProviderInterface; +use Drupal\Core\Plugin\Context\EntityContext; use Drupal\Core\StringTranslation\StringTranslationTrait; /** @@ -36,8 +35,7 @@ class MediaContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getRuntimeContexts(array $unqualified_context_ids) { - $context_definition = new ContextDefinition('entity:media', NULL, FALSE); - $context = new Context($context_definition, $this->media); + $context = EntityContext::fromEntity($this->media); return ['@islandora.media_route_context_provider:media' => $context]; } @@ -45,7 +43,7 @@ class MediaContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getAvailableContexts() { - $context = new Context(new ContextDefinition('entity:media', $this->t('Media from entity hook'))); + $context = EntityContext::fromEntityTypeId('entity:media', $this->t('Media from entity hook')); return ['@islandora.media_route_context_provider:media' => $context]; } diff --git a/src/ContextProvider/MediaRouteContextProvider.php b/src/ContextProvider/MediaRouteContextProvider.php index 3a731760..cab44a6c 100644 --- a/src/ContextProvider/MediaRouteContextProvider.php +++ b/src/ContextProvider/MediaRouteContextProvider.php @@ -4,8 +4,9 @@ namespace Drupal\islandora\ContextProvider; 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\Plugin\Context\EntityContext; +use Drupal\Core\Plugin\Context\EntityContextDefinition; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\media\Entity\Media; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -39,7 +40,7 @@ class MediaRouteContextProvider implements ContextProviderInterface { */ public function getRuntimeContexts(array $unqualified_context_ids) { $result = []; - $context_definition = new ContextDefinition('entity:media', NULL, FALSE); + $context_definition = EntityContextDefinition::fromEntityTypeId('entity:media')->setLabel(NULL)->setRequired(FALSE); $value = NULL; // Hack the media out of the route. @@ -70,7 +71,7 @@ class MediaRouteContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getAvailableContexts() { - $context = new Context(new ContextDefinition('entity:media', $this->t('Media from URL'))); + $context = EntityContext::fromEntityTypeId('entity:media', $this->t('Media from URL')); return ['media' => $context]; } diff --git a/src/ContextProvider/NodeContextProvider.php b/src/ContextProvider/NodeContextProvider.php index 637e4888..04122078 100644 --- a/src/ContextProvider/NodeContextProvider.php +++ b/src/ContextProvider/NodeContextProvider.php @@ -3,9 +3,8 @@ namespace Drupal\islandora\ContextProvider; use Drupal\node\NodeInterface; -use Drupal\Core\Plugin\Context\Context; -use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Plugin\Context\ContextProviderInterface; +use Drupal\Core\Plugin\Context\EntityContext; use Drupal\Core\StringTranslation\StringTranslationTrait; /** @@ -36,8 +35,7 @@ class NodeContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getRuntimeContexts(array $unqualified_context_ids) { - $context_definition = new ContextDefinition('entity:node', NULL, FALSE); - $context = new Context($context_definition, $this->node); + $context = EntityContext::fromEntity($this->node); return ['@node.node_route_context:node' => $context]; } @@ -45,7 +43,7 @@ class NodeContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getAvailableContexts() { - $context = new Context(new ContextDefinition('entity:node', $this->t('Node from entity hook'))); + $context = EntityContext::fromEntityTypeId('entity:node', $this->t('Node from entity hook')); return ['@node.node_route_context:node' => $context]; } diff --git a/src/ContextProvider/TermContextProvider.php b/src/ContextProvider/TermContextProvider.php index 7a1e6b79..0b51a0d2 100644 --- a/src/ContextProvider/TermContextProvider.php +++ b/src/ContextProvider/TermContextProvider.php @@ -3,9 +3,8 @@ namespace Drupal\islandora\ContextProvider; use Drupal\taxonomy\TermInterface; -use Drupal\Core\Plugin\Context\Context; -use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Plugin\Context\ContextProviderInterface; +use Drupal\Core\Plugin\Context\EntityContext; use Drupal\Core\StringTranslation\StringTranslationTrait; /** @@ -36,8 +35,7 @@ class TermContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getRuntimeContexts(array $unqualified_context_ids) { - $context_definition = new ContextDefinition('entity:taxonomy_term', NULL, FALSE); - $context = new Context($context_definition, $this->term); + $context = EntityContext::fromEntity($this->term); return ['@islandora.taxonomy_term_route_context_provider:taxonomy_term' => $context]; } @@ -45,7 +43,7 @@ class TermContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getAvailableContexts() { - $context = new Context(new ContextDefinition('entity:taxonomy_term', $this->t('Term from entity hook'))); + $context = EntityContext::fromEntityTypeId('entity:taxonomy_term', $this->t('Term from entity hook')); return ['@islandora.taxonomy_term_route_context_provider:taxonomy_term' => $context]; } diff --git a/src/ContextProvider/TermRouteContextProvider.php b/src/ContextProvider/TermRouteContextProvider.php index 59313523..dc3a7ec9 100644 --- a/src/ContextProvider/TermRouteContextProvider.php +++ b/src/ContextProvider/TermRouteContextProvider.php @@ -4,8 +4,9 @@ namespace Drupal\islandora\ContextProvider; 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\Plugin\Context\EntityContext; +use Drupal\Core\Plugin\Context\EntityContextDefinition; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -24,7 +25,7 @@ class TermRouteContextProvider implements ContextProviderInterface { protected $routeMatch; /** - * Constructs a new FileRouteContextProvider. + * Constructs a new TermRouteContextProvider. * * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The route match object. @@ -37,10 +38,10 @@ class TermRouteContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getRuntimeContexts(array $unqualified_context_ids) { - $context_definition = new ContextDefinition('entity:taxonomy_term', NULL, FALSE); + $context_definition = EntityContextDefinition::fromEntityTypeId('entity:taxonomy_term')->setLabel(NULL)->setRequired(FALSE); $value = NULL; - // Hack the file out of the route. + // Hack the taxonomy term out of the route. $route_object = $this->routeMatch->getRouteObject(); if ($route_object) { $route_contexts = $route_object->getOption('parameters'); @@ -64,7 +65,7 @@ class TermRouteContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getAvailableContexts() { - $context = new Context(new ContextDefinition('entity:taxonomy_term', $this->t('Term from URL'))); + $context = EntityContext::fromEntityTypeId('entity:taxonomy_term', $this->t('Term from URL')); return ['taxonomy_term' => $context]; }