You are here

public function ForumLeafConstraintValidator::validate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/forum/src/Plugin/Validation/Constraint/ForumLeafConstraintValidator.php \Drupal\forum\Plugin\Validation\Constraint\ForumLeafConstraintValidator::validate()

Checks if the passed value is valid.

Parameters

mixed $value The value that should be validated:

Constraint $constraint The constraint for the validation:

Overrides ConstraintValidatorInterface::validate

File

core/modules/forum/src/Plugin/Validation/Constraint/ForumLeafConstraintValidator.php, line 21
Contains \Drupal\forum\Plugin\Validation\Constraint\ForumLeafConstraintValidator.

Class

ForumLeafConstraintValidator
Validates the ForumLeaf constraint.

Namespace

Drupal\forum\Plugin\Validation\Constraint

Code

public function validate($items, Constraint $constraint) {
  $item = $items
    ->first();
  if (!isset($item)) {
    return NULL;
  }

  // Verify that a term has been selected.
  if (!$item->entity) {
    $this->context
      ->addViolation($constraint->selectForum);
  }

  // The forum_container flag must not be set.
  if (!empty($item->entity->forum_container->value)) {
    $this->context
      ->addViolation($constraint->noLeafMessage, array(
      '%forum' => $item->entity
        ->getName(),
    ));
  }
}