You are here

class TestPageDisplayVariantSubscriber in Drupal 9

Same name and namespace in other branches
  1. 8 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 14

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() {
    $events[RenderEvents::SELECT_PAGE_DISPLAY_VARIANT][] = [
      'onSelectPageDisplayVariant',
    ];
    return $events;
  }

}

Members