-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrated Context Reaction with Triplestore Actions
- Loading branch information
1 parent
82a6a9d
commit ea58f6c
Showing
16 changed files
with
756 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Drupal\triplestore_indexer\ContextProvider; | ||
|
||
use Drupal\Core\Plugin\Context\ContextProviderInterface; | ||
use Drupal\Core\Plugin\Context\EntityContext; | ||
use Drupal\Core\StringTranslation\StringTranslationTrait; | ||
use Drupal\media\MediaInterface; | ||
|
||
/** | ||
* Sets the provided media as a context. | ||
*/ | ||
class MediaContextProvider implements ContextProviderInterface { | ||
|
||
use StringTranslationTrait; | ||
|
||
/** | ||
* Media to provide in a context. | ||
* | ||
* @var \Drupal\media\MediaInterface | ||
*/ | ||
protected $media; | ||
|
||
/** | ||
* Constructs a new MediaRouteContext. | ||
* | ||
* @var \Drupal\media\MediaInterface $media | ||
* The media to provide in a context. | ||
*/ | ||
public function __construct(MediaInterface $media) { | ||
$this->media = $media; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getRuntimeContexts(array $unqualified_context_ids) { | ||
$context = EntityContext::fromEntity($this->media); | ||
return ['@triplestore_indexer.media_route_context_provider:media' => $context]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAvailableContexts() { | ||
$context = EntityContext::fromEntityType(\Drupal::entityTypeManager()->getDefinition('media'), $this->t('Media from URL')); | ||
return ['@triplestore_indexer.media_route_context_provider:media' => $context]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace Drupal\triplestore_indexer\ContextProvider; | ||
|
||
use Drupal\Core\Cache\CacheableMetadata; | ||
use Drupal\Core\Plugin\Context\Context; | ||
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; | ||
use Drupal\media\Entity\Media; | ||
|
||
/** | ||
* Sets the current media as a context on media routes. | ||
*/ | ||
class MediaRouteContextProvider implements ContextProviderInterface { | ||
|
||
use StringTranslationTrait; | ||
|
||
/** | ||
* The route match object. | ||
* | ||
* @var \Drupal\Core\Routing\RouteMatchInterface | ||
*/ | ||
protected $routeMatch; | ||
|
||
/** | ||
* Constructs a new MediaRouteContextProvider. | ||
* | ||
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match | ||
* The route match object. | ||
*/ | ||
public function __construct(RouteMatchInterface $route_match) { | ||
$this->routeMatch = $route_match; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getRuntimeContexts(array $unqualified_context_ids) { | ||
$context_definition = EntityContextDefinition::fromEntityTypeId('media')->setLabel(NULL)->setRequired(FALSE); | ||
$value = NULL; | ||
|
||
$route_object = $this->routeMatch->getRouteObject(); | ||
if ($route_object) { | ||
$route_contexts = $route_object->getOption('parameters'); | ||
if ($route_contexts && isset($route_contexts['media'])) { | ||
$media = $this->routeMatch->getParameter('media'); | ||
if ($media) { | ||
$value = $media; | ||
} | ||
} | ||
elseif ($this->routeMatch->getRouteName() == 'entity.media.add_form') { | ||
$media_type = $this->routeMatch->getParameter('media_type'); | ||
$value = Media::create(['bundle' => $media_type->id()]); | ||
} | ||
} | ||
|
||
$cacheability = new CacheableMetadata(); | ||
$cacheability->setCacheContexts(['route']); | ||
|
||
$context = new Context($context_definition, $value); | ||
$context->addCacheableDependency($cacheability); | ||
return ['media' => $context]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAvailableContexts() { | ||
$context = EntityContext::fromEntityType(\Drupal::entityTypeManager()->getDefinition('media'), $this->t('Media from URL')); | ||
return ['media' => $context]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Drupal\triplestore_indexer\ContextProvider; | ||
|
||
use Drupal\Core\Plugin\Context\ContextProviderInterface; | ||
use Drupal\Core\Plugin\Context\EntityContext; | ||
use Drupal\Core\StringTranslation\StringTranslationTrait; | ||
use Drupal\node\NodeInterface; | ||
|
||
/** | ||
* Sets the provided media as a context. | ||
*/ | ||
class NodeContextProvider implements ContextProviderInterface { | ||
|
||
use StringTranslationTrait; | ||
|
||
/** | ||
* Node to provide in a context. | ||
* | ||
* @var \Drupal\node\NodeInterface | ||
*/ | ||
protected $node; | ||
|
||
/** | ||
* Constructs a new NodeContextProvider. | ||
* | ||
* @var \Drupal\node\NodeInterface $node | ||
* The node to provide in a context. | ||
*/ | ||
public function __construct(NodeInterface $node) { | ||
$this->node = $node; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getRuntimeContexts(array $unqualified_context_ids) { | ||
$context = EntityContext::fromEntity($this->node); | ||
return ['@node.node_route_context:node' => $context]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAvailableContexts() { | ||
$context = EntityContext::fromEntityTypeId('node', $this->t('Node from entity hook')); | ||
return ['@node.node_route_context:node' => $context]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Drupal\triplestore_indexer\ContextProvider; | ||
|
||
use Drupal\Core\Plugin\Context\ContextProviderInterface; | ||
use Drupal\Core\Plugin\Context\EntityContext; | ||
use Drupal\Core\StringTranslation\StringTranslationTrait; | ||
use Drupal\taxonomy\TermInterface; | ||
|
||
/** | ||
* Sets the provided media as a context. | ||
*/ | ||
class TermContextProvider implements ContextProviderInterface { | ||
|
||
use StringTranslationTrait; | ||
|
||
/** | ||
* Term to provide in a context. | ||
* | ||
* @var \Drupal\term\TermInterface | ||
*/ | ||
protected $term; | ||
|
||
/** | ||
* Constructs a new TermContextProvider. | ||
* | ||
* @var \Drupal\term\TermInterface $term | ||
* The term to provide in a context. | ||
*/ | ||
public function __construct(TermInterface $term) { | ||
$this->term = $term; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getRuntimeContexts(array $unqualified_context_ids) { | ||
$context = EntityContext::fromEntity($this->term); | ||
return ['@triplestore_indexer.taxonomy_term_route_context_provider:taxonomy_term' => $context]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAvailableContexts() { | ||
$context = EntityContext::fromEntityTypeId('taxonomy_term', $this->t('Term from entity hook')); | ||
return ['@triplestore_indexer.taxonomy_term_route_context_provider:taxonomy_term' => $context]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Drupal\triplestore_indexer\ContextProvider; | ||
|
||
use Drupal\Core\Cache\CacheableMetadata; | ||
use Drupal\Core\Plugin\Context\Context; | ||
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; | ||
|
||
/** | ||
* Sets the current file as a context on file routes. | ||
*/ | ||
class TermRouteContextProvider implements ContextProviderInterface { | ||
|
||
use StringTranslationTrait; | ||
|
||
/** | ||
* The route match object. | ||
* | ||
* @var \Drupal\Core\Routing\RouteMatchInterface | ||
*/ | ||
protected $routeMatch; | ||
|
||
/** | ||
* Constructs a new TermRouteContextProvider. | ||
* | ||
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match | ||
* The route match object. | ||
*/ | ||
public function __construct(RouteMatchInterface $route_match) { | ||
$this->routeMatch = $route_match; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getRuntimeContexts(array $unqualified_context_ids) { | ||
$context_definition = EntityContextDefinition::fromEntityTypeId('taxonomy_term')->setLabel(NULL)->setRequired(FALSE); | ||
$value = NULL; | ||
|
||
$route_object = $this->routeMatch->getRouteObject(); | ||
if ($route_object) { | ||
$route_contexts = $route_object->getOption('parameters'); | ||
if ($route_contexts && isset($route_contexts['taxonomy_term'])) { | ||
$term = $this->routeMatch->getParameter('taxonomy_term'); | ||
if ($term) { | ||
$value = $term; | ||
} | ||
} | ||
} | ||
|
||
$cacheability = new CacheableMetadata(); | ||
$cacheability->setCacheContexts(['route']); | ||
|
||
$context = new Context($context_definition, $value); | ||
$context->addCacheableDependency($cacheability); | ||
return ['taxonomy_term' => $context]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAvailableContexts() { | ||
$context = EntityContext::fromEntityTypeId('taxonomy_term', $this->t('Term from URL')); | ||
return ['taxonomy_term' => $context]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.