You are here

class BlockPageDisplayVariantSubscriber in Context 8.4

Same name and namespace in other branches
  1. 8 src/EventSubscriber/BlockPageDisplayVariantSubscriber.php \Drupal\context\EventSubscriber\BlockPageDisplayVariantSubscriber
  2. 8.0 src/EventSubscriber/BlockPageDisplayVariantSubscriber.php \Drupal\context\EventSubscriber\BlockPageDisplayVariantSubscriber

Selects the block page display variant.

Hierarchy

Expanded class hierarchy of BlockPageDisplayVariantSubscriber

See also

\Drupal\block\Plugin\DisplayVariant\BlockPageVariant

1 string reference to 'BlockPageDisplayVariantSubscriber'
context.services.yml in ./context.services.yml
context.services.yml
1 service uses BlockPageDisplayVariantSubscriber
context.block_page_display_variant_subscriber in ./context.services.yml
Drupal\context\EventSubscriber\BlockPageDisplayVariantSubscriber

File

src/EventSubscriber/BlockPageDisplayVariantSubscriber.php, line 16

Namespace

Drupal\context\EventSubscriber
View 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

Namesort descending Modifiers Type Description Overrides
BlockPageDisplayVariantSubscriber::$contextManager private property The Context module context manager.
BlockPageDisplayVariantSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
BlockPageDisplayVariantSubscriber::onSelectPageDisplayVariant public function Selects the context block page display variant.
BlockPageDisplayVariantSubscriber::__construct public function Construct a block page display variant.