You are here

public function ContextDefinition::setConstraints 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::setConstraints()

Sets the array of validation constraints.

NOTE: This will override any previously set constraints. In most cases ContextDefinitionInterface::addConstraint() should be used instead.

Parameters

array $constraints: The array of constraints.

Return value

$this

Overrides ContextDefinitionInterface::setConstraints

See also

self::addConstraint()

File

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

Class

ContextDefinition
Defines a class for context definitions.

Namespace

Drupal\Core\Plugin\Context

Code

public function setConstraints(array $constraints) {

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