You are here

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

Gets a validation constraint.

Parameters

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

Return value

array A validation constraint definition which can be used for instantiating a \Symfony\Component\Validator\Constraint object.

Overrides ContextDefinitionInterface::getConstraint

1 call to ContextDefinition::getConstraint()
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 257

Class

ContextDefinition
Defines a class for context definitions.

Namespace

Drupal\Core\Plugin\Context

Code

public function getConstraint($constraint_name) {

  // If the backwards compatibility layer is present, delegate to that.
  $this
    ->initializeEntityContextDefinition();
  if ($this->entityContextDefinition) {
    return $this->entityContextDefinition
      ->getConstraint($constraint_name);
  }
  $constraints = $this
    ->getConstraints();
  return isset($constraints[$constraint_name]) ? $constraints[$constraint_name] : NULL;
}