class ContextReaction in Breadcrumb Manager 8
Class ContextReaction.
@BreadcrumbTitleResolver( id = "context_reaction", label = @Translation("Context Reaction"), description = @Translation("Resolve title from a Context reaction."), weight = 0, enabled = FALSE )
@package Drupal\breadcrumb_manager\Plugin\BreadcrumbTitleResolver
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\breadcrumb_manager\Plugin\BreadcrumbTitleResolverBase implements BreadcrumbTitleResolverInterface, ContainerFactoryPluginInterface uses DependencySerializationTrait
- class \Drupal\breadcrumb_manager_context\Plugin\BreadcrumbTitleResolver\ContextReaction
- class \Drupal\breadcrumb_manager\Plugin\BreadcrumbTitleResolverBase implements BreadcrumbTitleResolverInterface, ContainerFactoryPluginInterface uses DependencySerializationTrait
Expanded class hierarchy of ContextReaction
File
- modules/
breadcrumb_manager_context/ src/ Plugin/ BreadcrumbTitleResolver/ ContextReaction.php, line 28
Namespace
Drupal\breadcrumb_manager_context\Plugin\BreadcrumbTitleResolverView source
class ContextReaction extends BreadcrumbTitleResolverBase {
/**
* The Module Handler Service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The Context Manager Service.
*
* @var \Drupal\context\ContextManager
*/
protected $contextManager;
/**
* The Request Stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* Breadcrumb Manager cache bin.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cache;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler, ContextManager $context_manager, RequestStack $request_stack, CacheBackendInterface $cache) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->moduleHandler = $module_handler;
$this->contextManager = $context_manager;
$this->requestStack = $request_stack;
$this->cache = $cache;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('module_handler'), $container
->get('context.manager'), $container
->get('request_stack'), $container
->get('cache.breadcrumb_manager'));
}
/**
* {@inheritdoc}
*/
public function isActive() {
if ($this->moduleHandler
->moduleExists('context') === FALSE) {
return FALSE;
}
return parent::isActive();
}
/**
* {@inheritdoc}
*/
public function getTitle($path, Request $request, RouteMatchInterface $route_match) {
foreach ($this
->getReactions($path, $request) as $reaction) {
$title = $reaction
->execute();
if (!empty($title)) {
return $title;
}
}
return NULL;
}
/**
* Get reactions.
*
* @param string $path
* The path.
* @param \Symfony\Component\HttpFoundation\Request $request
* The Request.
*
* @return \Drupal\context\ContextReactionInterface[]
* An array of Context reactions.
*/
protected function getReactions($path, Request $request) {
$cid = "context:{$path}";
$cache = $this->cache
->get($cid);
if (!empty($cache->data)) {
return $cache->data;
}
$requestHasChanged = FALSE;
$currentRequest = $this->requestStack
->getCurrentRequest();
if ($currentRequest
->getPathInfo() !== $request
->getPathInfo()) {
// Pop out the original Request.
$orig = $this->requestStack
->pop();
// Assign original session to the new Request.
$request
->setSession($orig
->getSession());
// Switch the new Request with the old one and evaluate contexts again.
$this->requestStack
->push($request);
$this->contextManager
->evaluateContexts();
// Push the old Request back.
$this->requestStack
->push($orig);
// Mark Request as changed.
$requestHasChanged = TRUE;
}
$reactions = $this->contextManager
->getActiveReactions('breadcrumb');
$this->cache
->set($cid, $reactions, Cache::PERMANENT, [
'breadcrumb_manager',
'breadcrumb_manager_context',
]);
// If Request has changed, evaluate contexts again in order to avoid wrong
// reactions to be used.
if ($requestHasChanged) {
$this->contextManager
->evaluateContexts();
}
return $reactions;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BreadcrumbTitleResolverBase:: |
protected | property | 1 | |
BreadcrumbTitleResolverBase:: |
public | function |
Set active. Overrides BreadcrumbTitleResolverInterface:: |
|
ContextReaction:: |
protected | property | Breadcrumb Manager cache bin. | |
ContextReaction:: |
protected | property | The Context Manager Service. | |
ContextReaction:: |
protected | property | The Module Handler Service. | |
ContextReaction:: |
protected | property | The Request Stack. | |
ContextReaction:: |
public static | function |
Creates an instance of the plugin. Overrides BreadcrumbTitleResolverBase:: |
|
ContextReaction:: |
protected | function | Get reactions. | |
ContextReaction:: |
public | function |
Get title. Overrides BreadcrumbTitleResolverInterface:: |
|
ContextReaction:: |
public | function |
Is active. Overrides BreadcrumbTitleResolverBase:: |
|
ContextReaction:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. |