public function Context::validate

Same name in this branch

Overrides \Drupal\Component\Plugin\Context\Context::getConstraints().

Overrides Context::validate

File

drupal/core/lib/Drupal/Core/Plugin/Context/Context.php, line 87
Contains \Drupal\Core\Plugin\Context\Context.

Class

Context
A Drupal specific context wrapper class.

Namespace

Drupal\Core\Plugin\Context

Code

public function validate() {
  $validator = Validation::createValidatorBuilder()
    ->setTranslator(new DrupalTranslator())
    ->getValidator();

  // @todo We won't need to special case "entity" here once #1868004 lands.
  if (!empty($this->contextDefinition['type']) && $this->contextDefinition['type'] == 'entity') {
    $value = $this
      ->getTypedContext();
  }
  else {
    $value = $this
      ->getContextValue();
  }
  return $validator
    ->validateValue($value, $this
    ->getConstraints());
}