Browse Source

replace deprecated context definition method - per https://www.drupal.org/node/2976400

d9_islandora
Eli Zoller 4 years ago
parent
commit
0b165a8278
  1. 8
      src/ContextProvider/FileContextProvider.php
  2. 8
      src/ContextProvider/FileRouteContextProvider.php
  3. 8
      src/ContextProvider/MediaContextProvider.php
  4. 7
      src/ContextProvider/MediaRouteContextProvider.php
  5. 8
      src/ContextProvider/NodeContextProvider.php
  6. 8
      src/ContextProvider/TermContextProvider.php
  7. 11
      src/ContextProvider/TermRouteContextProvider.php

8
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];
}

8
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];
}

8
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];
}

7
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];
}

8
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];
}

8
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];
}

11
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];
}

Loading…
Cancel
Save