public ContextDefinition::__construct(array$values)
Constructs a new context definition object.
array $values: An associative array with the following keys:
\Exception Thrown when the class key is specified with a non ContextDefinitionInterface implementing class.
Overrides Plugin::__construct
public function __construct(array $values) { $values += array( 'required' => TRUE, 'multiple' => FALSE, 'default_value' => NULL, ); // Annotation classes extract data from passed annotation classes directly // used in the classes they pass to. foreach (['label', 'description'] as $key) { // @todo Remove this workaround in https://www.drupal.org/node/2362727. if (isset($values[$key]) && $values[$key] instanceof TranslatableMarkup) { $values[$key] = (string) $values[$key]->get(); } else { $values[$key] = NULL; } } if (isset($values['class']) && !in_array('Drupal\Core\Plugin\Context\ContextDefinitionInterface', class_implements($values['class']))) { throw new \Exception('ContextDefinition class must implement \Drupal\Core\Plugin\Context\ContextDefinitionInterface.'); } $class = isset($values['class']) ? $values['class'] : 'Drupal\Core\Plugin\Context\ContextDefinition'; $this->definition = new $class($values['value'], $values['label'], $values['required'], $values['multiple'], $values['description'], $values['default_value']); }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Annotation!ContextDefinition.php/function/ContextDefinition::__construct/8.1.x