interface ContextHandlerInterface (View source)

Provides an interface for handling sets of contexts.

Methods

array
filterPluginDefinitionsByContexts(array $contexts, array $definitions)

Determines plugins whose constraints are satisfied by a set of contexts.

bool
checkRequirements(array $contexts, array $requirements)

Checks a set of requirements against a set of contexts.

getMatchingContexts(array $contexts, ContextDefinitionInterface $definition)

Determines which contexts satisfy the constraints of a given definition.

applyContextMapping(ContextAwarePluginInterface $plugin, ContextInterface[] $contexts, array $mappings = [])

Prepares a plugin for evaluation.

Details

array filterPluginDefinitionsByContexts(array $contexts, array $definitions)

Determines plugins whose constraints are satisfied by a set of contexts.

Use context definition objects after https://www.drupal.org/node/2281635.

Parameters

array $contexts

An array of contexts.

array $definitions

An array of plugin definitions.

Return Value

array

An array of plugin definitions.

bool checkRequirements(array $contexts, array $requirements)

Checks a set of requirements against a set of contexts.

Use context definition objects after https://www.drupal.org/node/2281635.

Parameters

array $contexts

An array of available contexts.

array $requirements

An array of requirements.

Return Value

bool

TRUE if all of the requirements are satisfied by the context, FALSE otherwise.

ContextInterface[] getMatchingContexts(array $contexts, ContextDefinitionInterface $definition)

Determines which contexts satisfy the constraints of a given definition.

Use context definition objects after https://www.drupal.org/node/2281635.

Parameters

array $contexts

An array of contexts.

ContextDefinitionInterface $definition

The definition to satisfy.

Return Value

ContextInterface[]

An array of matching contexts.

applyContextMapping(ContextAwarePluginInterface $plugin, ContextInterface[] $contexts, array $mappings = [])

Prepares a plugin for evaluation.

Parameters

ContextAwarePluginInterface $plugin

A plugin about to be evaluated.

ContextInterface[] $contexts

An array of contexts to set on the plugin. They will only be set if they match the plugin's context definitions.

array $mappings

(optional) A mapping of the expected assignment names to their context names. For example, if one of the $contexts is named 'current_user', but the plugin expects a context named 'user', then this map would contain 'user' => 'current_user'.

Exceptions

ContextException
MissingValueContextException