interface ContextAwarePluginInterface

Same name in this branch
  1. 9 core/lib/Drupal/Core/Plugin/ContextAwarePluginInterface.php \Drupal\Core\Plugin\ContextAwarePluginInterface
Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Plugin/ContextAwarePluginInterface.php \Drupal\Core\Plugin\ContextAwarePluginInterface
  2. 8.9.x core/lib/Drupal/Component/Plugin/ContextAwarePluginInterface.php \Drupal\Component\Plugin\ContextAwarePluginInterface
  3. 10 core/lib/Drupal/Core/Plugin/ContextAwarePluginInterface.php \Drupal\Core\Plugin\ContextAwarePluginInterface
  4. 10 core/lib/Drupal/Component/Plugin/ContextAwarePluginInterface.php \Drupal\Component\Plugin\ContextAwarePluginInterface
  5. 11.x core/lib/Drupal/Core/Plugin/ContextAwarePluginInterface.php \Drupal\Core\Plugin\ContextAwarePluginInterface
  6. 11.x core/lib/Drupal/Component/Plugin/ContextAwarePluginInterface.php \Drupal\Component\Plugin\ContextAwarePluginInterface

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.

Hierarchy

Expanded class hierarchy of ContextAwarePluginInterface

All classes that implement ContextAwarePluginInterface

Related topics

1 file declares its use of ContextAwarePluginInterface
ContextAwarePluginInterface.php in core/lib/Drupal/Core/Plugin/ContextAwarePluginInterface.php

File

core/lib/Drupal/Component/Plugin/ContextAwarePluginInterface.php, line 15

Namespace

Drupal\Component\Plugin
View source
interface ContextAwarePluginInterface extends PluginInspectionInterface {
    
    /**
     * Gets the context definitions of the plugin.
     *
     * @return \Drupal\Component\Plugin\Context\ContextDefinitionInterface[]
     *   The array of context definitions, keyed by context name.
     */
    public function getContextDefinitions();
    
    /**
     * Gets a specific context definition of the plugin.
     *
     * @param string $name
     *   The name of the context in the plugin definition.
     *
     * @return \Drupal\Component\Plugin\Context\ContextDefinitionInterface
     *   The definition against which the context value must validate.
     *
     * @throws \Drupal\Component\Plugin\Exception\ContextException
     *   If the requested context is not defined.
     */
    public function getContextDefinition($name);
    
    /**
     * Gets the defined contexts.
     *
     * @return array
     *   The set context objects.
     *
     * @throws \Drupal\Component\Plugin\Exception\ContextException
     *   If contexts are defined but not set.
     */
    public function getContexts();
    
    /**
     * Gets a defined context.
     *
     * @param string $name
     *   The name of the context in the plugin definition.
     *
     * @return \Drupal\Component\Plugin\Context\ContextInterface
     *   The context object.
     *
     * @throws \Drupal\Component\Plugin\Exception\ContextException
     *   If the requested context is not set.
     */
    public function getContext($name);
    
    /**
     * Gets the values for all defined contexts.
     *
     * @return array
     *   An array of set context values, keyed by context name. If a context is
     *   unset its value is returned as NULL.
     */
    public function getContextValues();
    
    /**
     * Gets the value for a defined context.
     *
     * @param string $name
     *   The name of the context in the plugin configuration.
     *
     * @return mixed
     *   The currently set context value.
     *
     * @throws \Drupal\Component\Plugin\Exception\ContextException
     *   If the requested context is not set.
     */
    public function getContextValue($name);
    
    /**
     * Set a context on this plugin.
     *
     * @param string $name
     *   The name of the context in the plugin configuration.
     * @param \Drupal\Component\Plugin\Context\ContextInterface $context
     *   The context object to set.
     */
    public function setContext($name, ContextInterface $context);
    
    /**
     * Sets the value for a defined context.
     *
     * @param string $name
     *   The name of the context in the plugin definition.
     * @param mixed $value
     *   The value to set the context to. The value has to validate against the
     *   provided context definition.
     *
     * @return $this
     *   A context aware plugin object for chaining.
     *
     * @throws \Drupal\Component\Plugin\Exception\ContextException
     *   If the value does not pass validation.
     */
    public function setContextValue($name, $value);
    
    /**
     * Validates the set values for the defined contexts.
     *
     * @return \Symfony\Component\Validator\ConstraintViolationListInterface
     *   A list of constraint violations. If the list is empty, validation
     *   succeeded.
     */
    public function validateContexts();
    
    /**
     * Gets a mapping of the expected assignment names to their context names.
     *
     * @return 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'.
     */
    public function getContextMapping();
    
    /**
     * Sets a mapping of the expected assignment names to their context names.
     *
     * @param array $context_mapping
     *   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'.
     *
     * @return $this
     */
    public function setContextMapping(array $context_mapping);

}

Members

Title Sort descending Modifiers Object type Summary Overrides
ContextAwarePluginInterface::getContext public function Gets a defined context. 1
ContextAwarePluginInterface::getContextDefinition public function Gets a specific context definition of the plugin. 2
ContextAwarePluginInterface::getContextDefinitions public function Gets the context definitions of the plugin. 2
ContextAwarePluginInterface::getContextMapping public function Gets a mapping of the expected assignment names to their context names.
ContextAwarePluginInterface::getContexts public function Gets the defined contexts. 1
ContextAwarePluginInterface::getContextValue public function Gets the value for a defined context. 1
ContextAwarePluginInterface::getContextValues public function Gets the values for all defined contexts. 1
ContextAwarePluginInterface::setContext public function Set a context on this plugin. 2
ContextAwarePluginInterface::setContextMapping public function Sets a mapping of the expected assignment names to their context names.
ContextAwarePluginInterface::setContextValue public function Sets the value for a defined context. 1
ContextAwarePluginInterface::validateContexts public function Validates the set values for the defined contexts. 1
PluginInspectionInterface::getPluginDefinition public function Gets the definition of the plugin implementation. 6
PluginInspectionInterface::getPluginId public function Gets the plugin_id of the plugin instance. 2

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.