abstract class ContextAwarePluginBase

Same name in this branch
  1. 8.x drupal/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php \Drupal\Core\Plugin\ContextAwarePluginBase
  2. 8.x drupal/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php \Drupal\Component\Plugin\ContextAwarePluginBase

Drupal specific class for plugins that use context.

This class specifically overrides setContextValue to use the core version of the Context class. This code is exactly the same as what is in Component ContextAwarePluginBase but it is using a different Context class.

Hierarchy

Expanded class hierarchy of ContextAwarePluginBase

4 files declare their use of ContextAwarePluginBase
ExecutablePluginBase.php in drupal/core/lib/Drupal/Core/Executable/ExecutablePluginBase.php
Contains \Drupal\Core\Executable\ExecutablePluginBase.
MockComplexContextBlock.php in drupal/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/plugin_test/mock_block/MockComplexContextBlock.php
Contains \Drupal\plugin_test\Plugin\plugin_test\mock_block\MockComplexContextBlock.
MockUserNameBlock.php in drupal/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/plugin_test/mock_block/MockUserNameBlock.php
Contains \Drupal\plugin_test\Plugin\plugin_test\mock_block\MockUserNameBlock.
TypedDataStringBlock.php in drupal/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/plugin_test/mock_block/TypedDataStringBlock.php
Contains \Drupal\plugin_test\Plugin\plugin_test\mock_block\TypedDataStringBlock.

File

drupal/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php, line 22
Contains \Drupal\Core\Plugin\ContextAwarePluginBase

Namespace

Drupal\Core\Plugin
View source
abstract class ContextAwarePluginBase extends PluginBase {

  /**
   * Override of \Drupal\Component\Plugin\ContextAwarePluginBase::__construct().
   */
  public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
    $context = array();
    if (isset($configuration['context'])) {
      $context = $configuration['context'];
      unset($configuration['context']);
    }
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    foreach ($context as $key => $value) {
      $context_definition = $this
        ->getContextDefinition($key);
      $this->context[$key] = new Context($context_definition);
      $this->context[$key]
        ->setContextValue($value);
    }
  }

  /**
   * Override of \Drupal\Component\Plugin\ContextAwarePluginBase::setContextValue().
   */
  public function setContextValue($name, $value) {
    $context_definition = $this
      ->getContextDefinition($name);

    // Use the Drupal specific context class.
    $this->context[$name] = new Context($context_definition);
    $this->context[$name]
      ->setContextValue($value);

    // Verify the provided value validates.
    if ($this->context[$name]
      ->validate()
      ->count() > 0) {
      throw new PluginException("The provided context value does not pass validation.");
    }
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContextAwarePluginBase::$context protected property The data objects representing the context of this plugin.
ContextAwarePluginBase::getContext public function Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::getContext(). Overrides ContextAwarePluginInterface::getContext
ContextAwarePluginBase::getContextDefinition public function Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::getContextDefinition(). Overrides ContextAwarePluginInterface::getContextDefinition
ContextAwarePluginBase::getContextDefinitions public function Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::getContextDefinitions(). Overrides ContextAwarePluginInterface::getContextDefinitions
ContextAwarePluginBase::getContexts public function Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::getContexts(). Overrides ContextAwarePluginInterface::getContexts
ContextAwarePluginBase::getContextValue public function Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::getContextValue(). Overrides ContextAwarePluginInterface::getContextValue
ContextAwarePluginBase::getContextValues public function Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::getContextValues(). Overrides ContextAwarePluginInterface::getContextValues
ContextAwarePluginBase::setContextValue public function Override of \Drupal\Component\Plugin\ContextAwarePluginBase::setContextValue(). Overrides ContextAwarePluginBase::setContextValue
ContextAwarePluginBase::validateContexts public function Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::valdidateContexts(). Overrides ContextAwarePluginInterface::validateContexts
ContextAwarePluginBase::__construct public function Override of \Drupal\Component\Plugin\ContextAwarePluginBase::__construct(). Overrides ContextAwarePluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin_id.
PluginBase::getPluginDefinition public function Returns the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Returns the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId