function ContextAwarePluginTrait::getContextDefinition

Same name in other branches
  1. 9 core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php \Drupal\Core\Plugin\ContextAwarePluginTrait::getContextDefinition()
  2. 11.x core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php \Drupal\Core\Plugin\ContextAwarePluginTrait::getContextDefinition()

Return value

\Drupal\Core\Plugin\Context\ContextDefinitionInterface

1 call to ContextAwarePluginTrait::getContextDefinition()
ContextAwarePluginTrait::getContext in core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php

File

core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php, line 140

Class

ContextAwarePluginTrait
Provides a trait to add context-aware functionality to plugins.

Namespace

Drupal\Core\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));
}

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