interface ContextProviderInterface (View source)

Defines an interface for providing plugin contexts.

Implementations only need to deal with unqualified context IDs so they only need to be unique in the context of a given service provider.

The fully qualified context ID then includes the service ID, e.g. "@service_id:unqualified_context_id".

Methods

getRuntimeContexts(array $unqualified_context_ids)

Gets runtime context values for the given context IDs.

getAvailableContexts()

Gets all available contexts for the purposes of configuration.

Details

ContextInterface[] getRuntimeContexts(array $unqualified_context_ids)

Gets runtime context values for the given context IDs.

For context-aware plugins to function correctly, all of the contexts that they require must be populated with values. So this method should set a value for each context that it adds. For example:

Parameters

array $unqualified_context_ids

The requested context IDs. The context provider must only return contexts for those IDs.

Return Value

ContextInterface[]

The determined available contexts, keyed by the unqualified context_id.

See also

ContextProviderInterface:getAvailableContexts()

ContextInterface[] getAvailableContexts()

Gets all available contexts for the purposes of configuration.

When a context aware plugin is being configured, the configuration UI must know which named contexts are potentially available, but does not care about the value, since the value can be different for each request, and might not be available at all during the configuration UI's request.

For example:

Return Value

ContextInterface[]

All available contexts keyed by the unqualified context ID.

See also

\Drupal\Core\Plugin\Context\ContextProviderInterface::getRuntimeContext()