class ForumLeafConstraintValidator

Same name in other branches
  1. 9 core/modules/forum/src/Plugin/Validation/Constraint/ForumLeafConstraintValidator.php \Drupal\forum\Plugin\Validation\Constraint\ForumLeafConstraintValidator
  2. 8.9.x core/modules/forum/src/Plugin/Validation/Constraint/ForumLeafConstraintValidator.php \Drupal\forum\Plugin\Validation\Constraint\ForumLeafConstraintValidator
  3. 10 core/modules/forum/src/Plugin/Validation/Constraint/ForumLeafConstraintValidator.php \Drupal\forum\Plugin\Validation\Constraint\ForumLeafConstraintValidator

Validates the ForumLeaf constraint.

Hierarchy

Expanded class hierarchy of ForumLeafConstraintValidator

File

core/modules/forum/src/Plugin/Validation/Constraint/ForumLeafConstraintValidator.php, line 11

Namespace

Drupal\forum\Plugin\Validation\Constraint
View source
class ForumLeafConstraintValidator extends ConstraintValidator {
    
    /**
     * {@inheritdoc}
     */
    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, [
                '%forum' => $item->entity
                    ->getName(),
            ]);
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
ForumLeafConstraintValidator::validate public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.