class PageDisplayVariantSelectionEvent extends Event implements RefinableCacheableDependencyInterface (View source)

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:

  • self::setPluginConfiguration()
  • self::setContexts()
  • self::addCacheableDependency()

Traits

Trait for \Drupal\Core\Cache\RefinableCacheableDependencyInterface.

Trait for \Drupal\Core\Cache\CacheableDependencyInterface.

Properties

protected string[] $cacheContexts

Cache contexts.

from  CacheableDependencyTrait
protected string[] $cacheTags

Cache tags.

from  CacheableDependencyTrait
protected int $cacheMaxAge

Cache max-age.

from  CacheableDependencyTrait
protected string $pluginId

The selected page display variant plugin ID.

protected array $pluginConfiguration

The configuration for the selected page display variant.

protected RouteMatchInterface $routeMatch

The current route match.

protected ContextInterface[] $contexts

An array of collected contexts to pass to the page display variant.

Methods

$this
setCacheability(CacheableDependencyInterface $cacheability)

Sets cacheability; useful for value object constructors.

getCacheTags()

{@inheritdoc}

addCacheableDependency($other_object)

{@inheritdoc}

addCacheContexts(array $cache_contexts)

{@inheritdoc}

addCacheTags(array $cache_tags)

{@inheritdoc}

__construct(string $plugin_id, RouteMatchInterface $route_match)

Constructs the page display variant plugin selection event.

$this
setPluginId(string $plugin_id)

The selected page display variant plugin ID.

string
getPluginId()

The selected page display variant plugin ID.

$this
setPluginConfiguration(array $configuration)

Set the configuration for the selected page display variant.

array
getPluginConfiguration()

Get the configuration for the selected page display variant.

getRouteMatch()

Gets the current route match.

getContexts()

Gets the contexts that were set during event dispatch.

$this
setContexts(array $contexts)

Sets the contexts to be passed to the page display variant.

Details

protected $this setCacheability(CacheableDependencyInterface $cacheability)

Sets cacheability; useful for value object constructors.

Parameters

CacheableDependencyInterface $cacheability

The cacheability to set.

Return Value

$this

getCacheTags()

{@inheritdoc}

getCacheContexts()

{@inheritdoc}

getCacheMaxAge()

{@inheritdoc}

addCacheableDependency($other_object)

{@inheritdoc}

Parameters

$other_object

addCacheContexts(array $cache_contexts)

{@inheritdoc}

Parameters

array $cache_contexts

addCacheTags(array $cache_tags)

{@inheritdoc}

Parameters

array $cache_tags

mergeCacheMaxAge($max_age)

{@inheritdoc}

Parameters

$max_age

__construct(string $plugin_id, RouteMatchInterface $route_match)

Constructs the page display variant plugin selection event.

Parameters

string $plugin_id

The ID of the page display variant plugin to use by default.

RouteMatchInterface $route_match

The current route match, for context.

$this setPluginId(string $plugin_id)

The selected page display variant plugin ID.

Parameters

string $plugin_id

The ID of the page display variant plugin to use.

Return Value

$this

string getPluginId()

The selected page display variant plugin ID.

Return Value

string

$this setPluginConfiguration(array $configuration)

Set the configuration for the selected page display variant.

Parameters

array $configuration

The configuration for the selected page display variant.

Return Value

$this

array getPluginConfiguration()

Get the configuration for the selected page display variant.

Return Value

array

RouteMatchInterface getRouteMatch()

Gets the current route match.

Return Value

RouteMatchInterface

The current route match, for context.

ContextInterface[] getContexts()

Gets the contexts that were set during event dispatch.

Return Value

ContextInterface[]

An array of set contexts, keyed by context name.

$this setContexts(array $contexts)

Sets the contexts to be passed to the page display variant.

Parameters

array $contexts

An array of contexts, keyed by context name.

Return Value

$this