public function ContextAwarePluginBase::getContexts

Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::getContexts().

Overrides ContextAwarePluginInterface::getContexts

File

drupal/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php, line 75
Contains \Drupal\Component\Plugin\ContextAwarePluginBase

Class

ContextAwarePluginBase
Base class for plugins that are context aware.

Namespace

Drupal\Component\Plugin

Code

public function getContexts() {
  $definitions = $this
    ->getContextDefinitions();
  if ($definitions && empty($this->context)) {
    throw new PluginException("There are no set contexts.");
  }
  $contexts = array();
  foreach (array_keys($definitions) as $name) {
    if (empty($this->context[$name])) {
      throw new PluginException("The {$name} context is not yet set.");
    }
    $contexts[$name] = $this->context[$name];
  }
  return $contexts;
}