RegistrationGroupSiblingValidator.php in RNG - Events and Registrations 8.2
Same filename and directory in other branches
Namespace
Drupal\rng\Plugin\Validation\ConstraintFile
src/Plugin/Validation/Constraint/RegistrationGroupSiblingValidator.phpView source
<?php
namespace Drupal\rng\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* Validates registration groups dependencies and conflicts.
*/
class RegistrationGroupSiblingValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($items, Constraint $constraint) {
/** @var $items \Drupal\Core\Field\EntityReferenceFieldItemList */
/** @var \Drupal\rng\Entity\GroupInterface $groups */
$groups = $items
->referencedEntities();
foreach ($groups as $k => $group) {
$t_args = [
'@group' => $group
->label(),
];
$siblings = $groups;
unset($siblings[$k]);
foreach ($siblings as $sibling) {
if (in_array($sibling, $group
->getConflictingGroups())) {
$t_args['@group_conflict'] = $sibling
->label();
$this->context
->addViolation($constraint->conflict, $t_args);
}
}
unset($t_args['@group_conflict']);
foreach ($group
->getDependentGroups() as $group_dependent) {
if (!in_array($group_dependent, $groups)) {
$t_args['@group_dependent'] = $group_dependent
->label();
$this->context
->addViolation($constraint->missingDependency, $t_args);
}
}
}
}
}
Classes
Name | Description |
---|---|
RegistrationGroupSiblingValidator | Validates registration groups dependencies and conflicts. |