BlockPageDisplayVariantSubscriber.php

Same filename in other branches
  1. 9 core/modules/block/src/EventSubscriber/BlockPageDisplayVariantSubscriber.php
  2. 8.9.x core/modules/block/src/EventSubscriber/BlockPageDisplayVariantSubscriber.php
  3. 11.x core/modules/block/src/EventSubscriber/BlockPageDisplayVariantSubscriber.php

Namespace

Drupal\block\EventSubscriber

File

core/modules/block/src/EventSubscriber/BlockPageDisplayVariantSubscriber.php

View source
<?php

namespace Drupal\block\EventSubscriber;

use Drupal\Core\Render\PageDisplayVariantSelectionEvent;
use Drupal\Core\Render\RenderEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Selects the block page display variant.
 *
 * @see \Drupal\block\Plugin\DisplayVariant\BlockPageVariant
 */
class BlockPageDisplayVariantSubscriber implements EventSubscriberInterface {
    
    /**
     * Selects the block page display variant.
     *
     * @param \Drupal\Core\Render\PageDisplayVariantSelectionEvent $event
     *   The event to process.
     */
    public function onSelectPageDisplayVariant(PageDisplayVariantSelectionEvent $event) {
        $event->setPluginId('block_page');
    }
    
    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents() : array {
        $events[RenderEvents::SELECT_PAGE_DISPLAY_VARIANT][] = [
            'onSelectPageDisplayVariant',
        ];
        return $events;
    }

}

Classes

Title Deprecated Summary
BlockPageDisplayVariantSubscriber Selects the block page display variant.

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