You are here

class BlockPageDisplayVariantSubscriber in Context groups 8

Same name and namespace in other branches
  1. 8.2 src/EventSubscriber/BlockPageDisplayVariantSubscriber.php \Drupal\context_groups\EventSubscriber\BlockPageDisplayVariantSubscriber

Class BlockPageDisplayVariantSubscriber.

@package Drupal\context_groups

Hierarchy

Expanded class hierarchy of BlockPageDisplayVariantSubscriber

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

File

src/EventSubscriber/BlockPageDisplayVariantSubscriber.php, line 16

Namespace

Drupal\context_groups\EventSubscriber
View source
class BlockPageDisplayVariantSubscriber implements EventSubscriberInterface {

  /**
   * Drupal\context\ContextManager definition.
   *
   * @var \Drupal\context\ContextManager
   */
  protected $contextManager;

  /**
   * Constructor.
   *
   * @param ContextManager $context_manager
   *   Context manager.
   */
  public function __construct(ContextManager $context_manager) {
    $this->contextManager = $context_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[RenderEvents::SELECT_PAGE_DISPLAY_VARIANT][] = [
      'onSelectPageDisplayVariant',
    ];
    return $events;
  }

  /**
   * Selects the context groups block page display variant.
   *
   * @param PageDisplayVariantSelectionEvent $event
   *   The event to process.
   */
  public function onSelectPageDisplayVariant(PageDisplayVariantSelectionEvent $event) {

    // Activate the context groups block page display variant.
    foreach ($this->contextManager
      ->getActiveReactions() as $reaction) {
      if ($reaction instanceof Blocks) {
        $event
          ->setPluginId('context_groups_block_page');
        break;
      }
    }
  }

}

Members