class BlockPageDisplayVariantSubscriber in Context 8.4
Same name and namespace in other branches
- 8 src/EventSubscriber/BlockPageDisplayVariantSubscriber.php \Drupal\context\EventSubscriber\BlockPageDisplayVariantSubscriber
- 8.0 src/EventSubscriber/BlockPageDisplayVariantSubscriber.php \Drupal\context\EventSubscriber\BlockPageDisplayVariantSubscriber
Selects the block page display variant.
Hierarchy
- class \Drupal\context\EventSubscriber\BlockPageDisplayVariantSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of BlockPageDisplayVariantSubscriber
See also
\Drupal\block\Plugin\DisplayVariant\BlockPageVariant
1 string reference to 'BlockPageDisplayVariantSubscriber'
1 service uses BlockPageDisplayVariantSubscriber
File
- src/
EventSubscriber/ BlockPageDisplayVariantSubscriber.php, line 16
Namespace
Drupal\context\EventSubscriberView source
class BlockPageDisplayVariantSubscriber implements EventSubscriberInterface {
/**
* The Context module context manager.
*
* @var \Drupal\context\ContextManager
*/
private $contextManager;
/**
* Construct a block page display variant.
*
* @param \Drupal\context\ContextManager $contextManager
* The Context manager.
*/
public function __construct(ContextManager $contextManager) {
$this->contextManager = $contextManager;
}
/**
* Selects the context block page display variant.
*
* @param \Drupal\Core\Render\PageDisplayVariantSelectionEvent $event
* The event to process.
*/
public function onSelectPageDisplayVariant(PageDisplayVariantSelectionEvent $event) {
// Activate the context block page display variant if any of the reactions
// is a blocks reaction.
foreach ($this->contextManager
->getActiveReactions() as $reaction) {
if ($reaction instanceof Blocks) {
$event
->setPluginId('context_block_page');
break;
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[RenderEvents::SELECT_PAGE_DISPLAY_VARIANT][] = [
'onSelectPageDisplayVariant',
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlockPageDisplayVariantSubscriber:: |
private | property | The Context module context manager. | |
BlockPageDisplayVariantSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
BlockPageDisplayVariantSubscriber:: |
public | function | Selects the context block page display variant. | |
BlockPageDisplayVariantSubscriber:: |
public | function | Construct a block page display variant. |