function ContextDefinition::__construct

Same name in this branch
  1. 11.x core/lib/Drupal/Core/Annotation/ContextDefinition.php \Drupal\Core\Annotation\ContextDefinition::__construct()
Same name in other branches
  1. 9 core/lib/Drupal/Core/Annotation/ContextDefinition.php \Drupal\Core\Annotation\ContextDefinition::__construct()
  2. 9 core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php \Drupal\Core\Plugin\Context\ContextDefinition::__construct()
  3. 8.9.x core/lib/Drupal/Core/Annotation/ContextDefinition.php \Drupal\Core\Annotation\ContextDefinition::__construct()
  4. 8.9.x core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php \Drupal\Core\Plugin\Context\ContextDefinition::__construct()
  5. 10 core/lib/Drupal/Core/Annotation/ContextDefinition.php \Drupal\Core\Annotation\ContextDefinition::__construct()
  6. 10 core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php \Drupal\Core\Plugin\Context\ContextDefinition::__construct()

Constructs a new context definition object.

Parameters

string $data_type: The required data type.

string|null|\Stringable $label: The label of this context definition for the UI.

bool $required: Whether the context definition is required.

bool $multiple: Whether the context definition is multivalue.

string|null $description: The description of this context definition for the UI.

mixed $default_value: The default value of this definition.

array $constraints: An array of constraints keyed by the constraint name and a value of an array constraint options or a NULL.

1 call to ContextDefinition::__construct()
EntityContextDefinition::__construct in core/lib/Drupal/Core/Plugin/Context/EntityContextDefinition.php
Constructs a new context definition object.
1 method overrides ContextDefinition::__construct()
EntityContextDefinition::__construct in core/lib/Drupal/Core/Plugin/Context/EntityContextDefinition.php
Constructs a new context definition object.

File

core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php, line 108

Class

ContextDefinition
Defines a class for context definitions.

Namespace

Drupal\Core\Plugin\Context

Code

public function __construct($data_type = 'any', $label = NULL, $required = TRUE, $multiple = FALSE, $description = NULL, $default_value = NULL, array $constraints = []) {
    $this->dataType = $data_type;
    $this->label = $label;
    $this->isRequired = $required;
    $this->isMultiple = $multiple;
    $this->description = $description;
    $this->defaultValue = $default_value;
    foreach ($constraints as $constraint_name => $options) {
        $this->addConstraint($constraint_name, $options);
    }
    assert(!str_starts_with($data_type, 'entity:') || $this instanceof EntityContextDefinition);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.