ForumLeafConstraintValidator.php in Drupal 8
File
core/modules/forum/src/Plugin/Validation/Constraint/ForumLeafConstraintValidator.php
View source
<?php
namespace Drupal\forum\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
class ForumLeafConstraintValidator extends ConstraintValidator {
public function validate($items, Constraint $constraint) {
$item = $items
->first();
if (!isset($item)) {
return NULL;
}
if (!$item->entity) {
$this->context
->addViolation($constraint->selectForum);
}
if (!empty($item->entity->forum_container->value)) {
$this->context
->addViolation($constraint->noLeafMessage, [
'%forum' => $item->entity
->getName(),
]);
}
}
}