Same filename and directory in other branches
- 8.9.x core/modules/system/tests/modules/display_variant_test/src/EventSubscriber/TestPageDisplayVariantSubscriber.php
- 9 core/modules/system/tests/modules/display_variant_test/src/EventSubscriber/TestPageDisplayVariantSubscriber.php
Namespace
Drupal\display_variant_test\EventSubscriber
File
core/modules/system/tests/modules/display_variant_test/src/EventSubscriber/TestPageDisplayVariantSubscriber.php
View source
<?php
namespace Drupal\display_variant_test\EventSubscriber;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\Render\PageDisplayVariantSelectionEvent;
use Drupal\Core\Render\RenderEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class TestPageDisplayVariantSubscriber implements EventSubscriberInterface {
public function onSelectPageDisplayVariant(PageDisplayVariantSelectionEvent $event) {
$event
->setPluginId('display_variant_test');
$event
->setPluginConfiguration([
'required_configuration' => 'A very important, required value.',
]);
$event
->addCacheTags([
'custom_cache_tag',
]);
$context = new Context(new ContextDefinition('string', NULL, TRUE), 'Explicitly passed in context.');
$event
->setContexts([
'context' => $context,
]);
}
public static function getSubscribedEvents() : array {
$events[RenderEvents::SELECT_PAGE_DISPLAY_VARIANT][] = [
'onSelectPageDisplayVariant',
];
return $events;
}
}
Classes