class RegistrationGroupSiblingValidator in RNG - Events and Registrations 8
Same name and namespace in other branches
- 8.2 src/Plugin/Validation/Constraint/RegistrationGroupSiblingValidator.php \Drupal\rng\Plugin\Validation\Constraint\RegistrationGroupSiblingValidator
- 3.x src/Plugin/Validation/Constraint/RegistrationGroupSiblingValidator.php \Drupal\rng\Plugin\Validation\Constraint\RegistrationGroupSiblingValidator
Validates registration groups dependencies and conflicts.
Hierarchy
- class \Drupal\rng\Plugin\Validation\Constraint\RegistrationGroupSiblingValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of RegistrationGroupSiblingValidator
File
- src/
Plugin/ Validation/ Constraint/ RegistrationGroupSiblingValidator.php, line 11
Namespace
Drupal\rng\Plugin\Validation\ConstraintView source
class RegistrationGroupSiblingValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($items, Constraint $constraint) {
/** @var $items \Drupal\Core\Field\EntityReferenceFieldItemList */
/** @var \Drupal\rng\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);
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RegistrationGroupSiblingValidator:: |
public | function | Checks if the passed value is valid. |