You are here

public function ContextAwarePluginTrait::getContextDefinition in Drupal 9

Return value

\Drupal\Core\Plugin\Context\ContextDefinitionInterface

2 calls to ContextAwarePluginTrait::getContextDefinition()
ContextAwarePluginBase::createContextFromConfiguration in core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php
ContextAwarePluginTrait::getContext in core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php

File

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

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));
}