public function RegistrationGroupSiblingValidator::validate in RNG - Events and Registrations 3.x
Same name and namespace in other branches
- 8.2 src/Plugin/Validation/Constraint/RegistrationGroupSiblingValidator.php \Drupal\rng\Plugin\Validation\Constraint\RegistrationGroupSiblingValidator::validate()
- 8 src/Plugin/Validation/Constraint/RegistrationGroupSiblingValidator.php \Drupal\rng\Plugin\Validation\Constraint\RegistrationGroupSiblingValidator::validate()
File
- src/
Plugin/ Validation/ Constraint/ RegistrationGroupSiblingValidator.php, line 16
Class
- RegistrationGroupSiblingValidator
- Validates registration groups dependencies and conflicts.
Namespace
Drupal\rng\Plugin\Validation\ConstraintCode
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);
}
}
}
}