class ContextHandler implements ContextHandlerInterface (View source)

Provides methods to handle sets of contexts.

Methods

array
filterPluginDefinitionsByContexts(array $contexts, array $definitions)

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

getContextDefinitions(array|ContextAwarePluginDefinitionInterface $plugin_definition)

Returns the context definitions associated with a plugin definition.

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.

Parameters

array $contexts

An array of contexts.

array $definitions

An array of plugin definitions.

Return Value

array

An array of plugin definitions.

protected ContextDefinitionInterface[]|null getContextDefinitions(array|ContextAwarePluginDefinitionInterface $plugin_definition)

Returns the context definitions associated with a plugin definition.

Parameters

array|ContextAwarePluginDefinitionInterface $plugin_definition

The plugin definition.

Return Value

ContextDefinitionInterface[]|null

The context definitions, or NULL if the plugin definition does not support contexts.

bool checkRequirements(array $contexts, array $requirements)

Checks a set of requirements against a set of contexts.

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.

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