You are here

public function ContextDefinition::__construct in Typed Data API enhancements 8

Constructs a new context definition object.

Parameters

array $values: An associative array with the following keys:

  • value: The required data type.
  • label: (optional) The UI label of this context definition.
  • required: (optional) Whether the context definition is required.
  • multiple: (optional) Whether the context definition is multivalue.
  • description: (optional) The UI description of this context definition.
  • default_value: (optional) The default value in case the underlying value is not set.
  • class: (optional) A custom ContextDefinitionInterface class.

Throws

\Exception Thrown when the class key is specified with a non ContextDefinitionInterface implementing class.

Overrides ContextDefinition::__construct

File

src/Context/Annotation/ContextDefinition.php, line 31

Class

ContextDefinition
Extends the core context definition annotation object for Typed Data.

Namespace

Drupal\typed_data\Context\Annotation

Code

public function __construct(array $values) {

  // Filter out any @Translation annotation objects.
  foreach ($values as $key => $value) {
    if ($value instanceof Translation) {
      $values[$key] = $value
        ->get();
    }
  }
  $this->definition = TypedDataContextDefinition::createFromArray($values);
}