You are here

public function ContextDefinition::addConstraint in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php \Drupal\Core\Plugin\Context\ContextDefinition::addConstraint()

Adds a validation constraint.

Parameters

string $constraint_name: The name of the constraint to add, i.e. its plugin id.

array|null $options: The constraint options as required by the constraint plugin, or NULL.

Return value

$this

Overrides ContextDefinitionInterface::addConstraint

1 call to ContextDefinition::addConstraint()
EntityContextDefinition::getConstraintObjects in core/lib/Drupal/Core/Plugin/Context/EntityContextDefinition.php
Extracts an array of constraints for a context definition object.

File

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

Class

ContextDefinition
Defines a class for context definitions.

Namespace

Drupal\Core\Plugin\Context

Code

public function addConstraint($constraint_name, $options = NULL) {

  // If the backwards compatibility layer is present, delegate to that.
  $this
    ->initializeEntityContextDefinition();
  if ($this->entityContextDefinition) {
    $this->entityContextDefinition
      ->addConstraint($constraint_name, $options);
  }
  $this->constraints[$constraint_name] = $options;
  return $this;
}