Drupal 8  8.0.2
ContextAwarePluginInterface Interface Reference
Inheritance diagram for ContextAwarePluginInterface:

Public Member Functions

 getContextDefinitions ()
 
 getContextDefinition ($name)
 
 getContexts ()
 
 getContext ($name)
 
 getContextValues ()
 
 getContextValue ($name)
 
 setContext ($name, ContextInterface $context)
 
 setContextValue ($name, $value)
 
 validateContexts ()
 
 getContextMapping ()
 
 setContextMapping (array $context_mapping)
 
- Public Member Functions inherited from PluginInspectionInterface
 getPluginId ()
 
 getPluginDefinition ()
 

Detailed Description

Interface for defining context aware plugins.

Context aware plugins can specify an array of context definitions keyed by context name at the plugin definition under the "context" key.

Member Function Documentation

getContext (   $name)

Gets a defined context.

Parameters
string$nameThe name of the context in the plugin definition.
Returns
The context object.
Exceptions
\Drupal\Component\Plugin\Exception\PluginExceptionIf the requested context is not set.

Implemented in ContextAwarePluginBase, and ContextAwarePluginBase.

getContextDefinition (   $name)

Gets a specific context definition of the plugin.

Parameters
string$nameThe name of the context in the plugin definition.
Returns
. The definition against which the context value must validate.
Exceptions
\Drupal\Component\Plugin\Exception\PluginExceptionIf the requested context is not defined.

Implemented in ContextAwarePluginBase, ContextAwarePluginBase, and ContextAwarePluginInterface.

getContextDefinitions ( )

Gets the context definitions of the plugin.

Returns
[] The array of context definitions, keyed by context name.

Implemented in ContextAwarePluginBase, ContextAwarePluginBase, and ContextAwarePluginInterface.

getContextMapping ( )

Gets a mapping of the expected assignment names to their context names.

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

Implemented in ContextAwarePluginBase.

getContexts ( )

Gets the defined contexts.

Returns
array The set context objects.
Exceptions
\Drupal\Component\Plugin\Exception\PluginExceptionIf contexts are defined but not set.

Implemented in ContextAwarePluginBase.

getContextValue (   $name)

Gets the value for a defined context.

Parameters
string$nameThe name of the context in the plugin configuration.
Returns
mixed The currently set context value.
Exceptions
\Drupal\Component\Plugin\Exception\PluginExceptionIf the requested context is not set.

Implemented in ContextAwarePluginBase.

getContextValues ( )

Gets the values for all defined contexts.

Returns
array An array of set context values, keyed by context name. If a context is unset its value is returned as NULL.

Implemented in ContextAwarePluginBase.

setContext (   $name,
ContextInterface  $context 
)

Set a context on this plugin.

Parameters
string$nameThe name of the context in the plugin configuration.
\Drupal\Component\Plugin\Context\ContextInterface$contextThe context object to set.

Implemented in ContextAwarePluginBase.

setContextMapping ( array  $context_mapping)

Sets a mapping of the expected assignment names to their context names.

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

Implemented in ContextAwarePluginBase.

setContextValue (   $name,
  $value 
)

Sets the value for a defined context.

Parameters
string$nameThe name of the context in the plugin definition.
mixed$valueThe value to set the context to. The value has to validate against the provided context definition.
Returns
. A context aware plugin object for chaining.
Exceptions
\Drupal\Component\Plugin\Exception\PluginExceptionIf the value does not pass validation.

Implemented in ContextAwarePluginBase, and ContextAwarePluginBase.

validateContexts ( )

Validates the set values for the defined contexts.

Returns
A list of constraint violations. If the list is empty, validation succeeded.

Implemented in ContextAwarePluginBase.


The documentation for this interface was generated from the following file: