class TestPageDisplayVariantSubscriber

Same name in other branches
  1. 9 core/modules/system/tests/modules/display_variant_test/src/EventSubscriber/TestPageDisplayVariantSubscriber.php \Drupal\display_variant_test\EventSubscriber\TestPageDisplayVariantSubscriber
  2. 8.9.x core/modules/system/tests/modules/display_variant_test/src/EventSubscriber/TestPageDisplayVariantSubscriber.php \Drupal\display_variant_test\EventSubscriber\TestPageDisplayVariantSubscriber
  3. 10 core/modules/system/tests/modules/display_variant_test/src/EventSubscriber/TestPageDisplayVariantSubscriber.php \Drupal\display_variant_test\EventSubscriber\TestPageDisplayVariantSubscriber

Selects the test page display variant.

Hierarchy

Expanded class hierarchy of TestPageDisplayVariantSubscriber

1 string reference to 'TestPageDisplayVariantSubscriber'
display_variant_test.services.yml in core/modules/system/tests/modules/display_variant_test/display_variant_test.services.yml
core/modules/system/tests/modules/display_variant_test/display_variant_test.services.yml
1 service uses TestPageDisplayVariantSubscriber
display_variant_test.page_display_variant_subscriber in core/modules/system/tests/modules/display_variant_test/display_variant_test.services.yml
Drupal\display_variant_test\EventSubscriber\TestPageDisplayVariantSubscriber

File

core/modules/system/tests/modules/display_variant_test/src/EventSubscriber/TestPageDisplayVariantSubscriber.php, line 16

Namespace

Drupal\display_variant_test\EventSubscriber
View source
class TestPageDisplayVariantSubscriber implements EventSubscriberInterface {
    
    /**
     * Selects the page display variant.
     *
     * @param \Drupal\Core\Render\PageDisplayVariantSelectionEvent $event
     *   The event to process.
     */
    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,
        ]);
    }
    
    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents() : array {
        $events[RenderEvents::SELECT_PAGE_DISPLAY_VARIANT][] = [
            'onSelectPageDisplayVariant',
        ];
        return $events;
    }

}

Members

Title Sort descending Modifiers Object type Summary
TestPageDisplayVariantSubscriber::getSubscribedEvents public static function
TestPageDisplayVariantSubscriber::onSelectPageDisplayVariant public function Selects the page display variant.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.