class ForumLeafConstraintValidator in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/forum/src/Plugin/Validation/Constraint/ForumLeafConstraintValidator.php \Drupal\forum\Plugin\Validation\Constraint\ForumLeafConstraintValidator
Validates the ForumLeaf constraint.
Hierarchy
- class \Symfony\Component\Validator\ConstraintValidator implements ConstraintValidatorInterface
- class \Drupal\forum\Plugin\Validation\Constraint\ForumLeafConstraintValidator
Expanded class hierarchy of ForumLeafConstraintValidator
File
- core/
modules/ forum/ src/ Plugin/ Validation/ Constraint/ ForumLeafConstraintValidator.php, line 16 - Contains \Drupal\forum\Plugin\Validation\Constraint\ForumLeafConstraintValidator.
Namespace
Drupal\forum\Plugin\Validation\ConstraintView 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, array(
'%forum' => $item->entity
->getName(),
));
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConstraintValidator:: |
protected | property | 3 | |
ConstraintValidator:: |
protected | function | Wrapper for {@link ExecutionContextInterface::buildViolation} that supports the 2.4 context API. | |
ConstraintValidator:: |
protected | function | Wrapper for {@link ExecutionContextInterface::buildViolation} that supports the 2.4 context API. | |
ConstraintValidator:: |
protected | function | Returns a string representation of the type of the value. | |
ConstraintValidator:: |
protected | function | Returns a string representation of the value. | |
ConstraintValidator:: |
protected | function | Returns a string representation of a list of values. | |
ConstraintValidator:: |
public | function |
Initializes the constraint validator. Overrides ConstraintValidatorInterface:: |
1 |
ConstraintValidator:: |
constant | Whether to cast objects with a "__toString()" method to strings. | ||
ConstraintValidator:: |
constant | Whether to format {@link \DateTime} objects as RFC-3339 dates ("Y-m-d H:i:s"). | ||
ForumLeafConstraintValidator:: |
public | function |
Checks if the passed value is valid. Overrides ConstraintValidatorInterface:: |