Skip to content

Instantly share code, notes, and snippets.

@EclipseGc
Last active August 29, 2015 14:02
Show Gist options
  • Save EclipseGc/029a1a9e68c5152f6166 to your computer and use it in GitHub Desktop.
Save EclipseGc/029a1a9e68c5152f6166 to your computer and use it in GitHub Desktop.
<?php
/**
* Constructs a new context definition object.
*
* @param array $values
* An associative array with the following keys:
* - value: The required data type.
* - required: (optional) Whether the context definition is required.
* - multiple: (optional) Whether the context definition is multivalue.
* - label: (optional) The UI label of this context definition.
* - description: (optional) The UI description of this context definition.
* - class: (optional) A custom ContextDefinitionInterface class.
* @throws \Exception
*/
public function __construct(array $values) {
$values += array(
'required' => TRUE,
'multiple' => FALSE,
'label' => NULL,
'description' => 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['required'], $values['multiple'], $values['label'], $values['description']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment