You are here

public function ContextAwarePluginBase::getContextDefinition in Drupal 8

Same name in this branch
  1. 8 core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php \Drupal\Core\Plugin\ContextAwarePluginBase::getContextDefinition()
  2. 8 core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php \Drupal\Component\Plugin\ContextAwarePluginBase::getContextDefinition()
Same name and namespace in other branches
  1. 9 core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php \Drupal\Component\Plugin\ContextAwarePluginBase::getContextDefinition()

Gets a specific context definition of the plugin.

Parameters

string $name: The name of the context in the plugin definition.

Return value

\Drupal\Component\Plugin\Context\ContextDefinitionInterface The definition against which the context value must validate.

Throws

\Drupal\Component\Plugin\Exception\PluginException If the requested context is not defined.

Overrides ContextAwarePluginInterface::getContextDefinition

4 calls to ContextAwarePluginBase::getContextDefinition()
ContextAwarePluginBase::createContextFromConfiguration in core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php
Creates context objects from any context mappings in configuration.
ContextAwarePluginBase::getContext in core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php
Gets a defined context.
ContextAwarePluginBase::getContextDefinition in core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php
ContextAwarePluginBase::setContextValue in core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php
Sets the value for a defined context.
1 method overrides ContextAwarePluginBase::getContextDefinition()
ContextAwarePluginBase::getContextDefinition in core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php

File

core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php, line 108

Class

ContextAwarePluginBase
Base class for plugins that are context aware.

Namespace

Drupal\Component\Plugin

Code

public function getContextDefinition($name) {
  $definition = $this
    ->getPluginDefinition();
  if ($definition instanceof ContextAwarePluginDefinitionInterface) {
    if ($definition
      ->hasContextDefinition($name)) {
      return $definition
        ->getContextDefinition($name);
    }
  }
  elseif (!empty($definition['context_definitions'][$name])) {
    return $definition['context_definitions'][$name];
  }
  throw new ContextException(sprintf("The %s context is not a valid context.", $name));
}