You are here

class PageDisplayVariantSelectionEvent in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Render/PageDisplayVariantSelectionEvent.php \Drupal\Core\Render\PageDisplayVariantSelectionEvent

Event fired when rendering main content, to select a page display variant.

Subscribers of this event can call the following setters to pass additional information along to the selected variant:

Hierarchy

Expanded class hierarchy of PageDisplayVariantSelectionEvent

See also

\Drupal\Core\Render\RenderEvents::SELECT_PAGE_DISPLAY_VARIANT

\Drupal\Core\Render\MainContent\HtmlRenderer

3 files declare their use of PageDisplayVariantSelectionEvent
BlockPageDisplayVariantSubscriber.php in core/modules/block/src/EventSubscriber/BlockPageDisplayVariantSubscriber.php
Contains \Drupal\block\EventSubscriber\BlockPageDisplayVariantSubscriber.
HtmlRenderer.php in core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php
Contains \Drupal\Core\Render\MainContent\HtmlRenderer.
TestPageDisplayVariantSubscriber.php in core/modules/system/tests/modules/display_variant_test/src/EventSubscriber/TestPageDisplayVariantSubscriber.php
Contains \Drupal\display_variant_test\EventSubscriber\TestPageDisplayVariantSubscriber.

File

core/lib/Drupal/Core/Render/PageDisplayVariantSelectionEvent.php, line 27
Contains \Drupal\Core\Render\PageDisplayVariantSelectionEvent.

Namespace

Drupal\Core\Render
View source
class PageDisplayVariantSelectionEvent extends Event implements RefinableCacheableDependencyInterface {
  use RefinableCacheableDependencyTrait;

  /**
   * The selected page display variant plugin ID.
   *
   * @var string
   */
  protected $pluginId;

  /**
   * The configuration for the selected page display variant.
   *
   * @var array
   */
  protected $pluginConfiguration = [];

  /**
   * The current route match.
   *
   * @var \Drupal\Core\Routing\RouteMatchInterface
   */
  protected $routeMatch;

  /**
   * An array of collected contexts to pass to the page display variant.
   *
   * @var \Drupal\Component\Plugin\Context\ContextInterface[]
   */
  protected $contexts = [];

  /**
   * Constructs the page display variant plugin selection event.
   *
   * @param string
   *   The ID of the page display variant plugin to use by default.
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The current route match, for context.
   */
  public function __construct($plugin_id, RouteMatchInterface $route_match) {
    $this->pluginId = $plugin_id;
    $this->routeMatch = $route_match;
  }

  /**
   * The selected page display variant plugin ID.
   *
   * @param string $plugin_id
   *   The ID of the page display variant plugin to use.
   *
   * @return $this
   */
  public function setPluginId($plugin_id) {
    $this->pluginId = $plugin_id;
    return $this;
  }

  /**
   * The selected page display variant plugin ID.
   *
   * @return string;
   */
  public function getPluginId() {
    return $this->pluginId;
  }

  /**
   * Set the configuration for the selected page display variant.
   *
   * @param array $configuration
   *   The configuration for the selected page display variant.
   *
   * @return $this
   */
  public function setPluginConfiguration(array $configuration) {
    $this->pluginConfiguration = $configuration;
    return $this;
  }

  /**
   * Get the configuration for the selected page display variant.
   *
   * @return array
   */
  public function getPluginConfiguration() {
    return $this->pluginConfiguration;
  }

  /**
   * Gets the current route match.
   *
   * @return \Drupal\Core\Routing\RouteMatchInterface
   *   The current route match, for context.
   */
  public function getRouteMatch() {
    return $this->routeMatch;
  }

  /**
   * Gets the contexts that were set during event dispatch.
   *
   * @return \Drupal\Component\Plugin\Context\ContextInterface[]
   *   An array of set contexts, keyed by context name.
   */
  public function getContexts() {
    return $this->contexts;
  }

  /**
   * Sets the contexts to be passed to the page display variant.
   *
   * @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
   *   An array of contexts, keyed by context name.
   *
   * @return $this
   */
  public function setContexts(array $contexts) {
    $this->contexts = $contexts;
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Event::$dispatcher private property
Event::$name private property
Event::$propagationStopped private property
Event::getDispatcher Deprecated public function Returns the EventDispatcher that dispatches this Event.
Event::getName Deprecated public function Gets the event's name.
Event::isPropagationStopped public function Returns whether further event listeners should be triggered.
Event::setDispatcher Deprecated public function Stores the EventDispatcher that dispatches this Event.
Event::setName Deprecated public function Sets the event's name property.
Event::stopPropagation public function Stops the propagation of the event to further event listeners.
PageDisplayVariantSelectionEvent::$contexts protected property An array of collected contexts to pass to the page display variant.
PageDisplayVariantSelectionEvent::$pluginConfiguration protected property The configuration for the selected page display variant.
PageDisplayVariantSelectionEvent::$pluginId protected property The selected page display variant plugin ID.
PageDisplayVariantSelectionEvent::$routeMatch protected property The current route match.
PageDisplayVariantSelectionEvent::getContexts public function Gets the contexts that were set during event dispatch.
PageDisplayVariantSelectionEvent::getPluginConfiguration public function Get the configuration for the selected page display variant.
PageDisplayVariantSelectionEvent::getPluginId public function The selected page display variant plugin ID.
PageDisplayVariantSelectionEvent::getRouteMatch public function Gets the current route match.
PageDisplayVariantSelectionEvent::setContexts public function Sets the contexts to be passed to the page display variant.
PageDisplayVariantSelectionEvent::setPluginConfiguration public function Set the configuration for the selected page display variant.
PageDisplayVariantSelectionEvent::setPluginId public function The selected page display variant plugin ID.
PageDisplayVariantSelectionEvent::__construct public function Constructs the page display variant plugin selection event.
RefinableCacheableDependencyTrait::$cacheContexts protected property Cache contexts.
RefinableCacheableDependencyTrait::$cacheMaxAge protected property Cache max-age.
RefinableCacheableDependencyTrait::$cacheTags protected property Cache tags.
RefinableCacheableDependencyTrait::addCacheableDependency public function 1
RefinableCacheableDependencyTrait::addCacheContexts public function
RefinableCacheableDependencyTrait::addCacheTags public function
RefinableCacheableDependencyTrait::getCacheContexts public function 4
RefinableCacheableDependencyTrait::getCacheMaxAge public function 4
RefinableCacheableDependencyTrait::getCacheTags public function 4
RefinableCacheableDependencyTrait::mergeCacheMaxAge public function