public static function Registrants::validateIdentityElement in RNG - Events and Registrations 8
Same name and namespace in other branches
- 8.2 src/Element/Registrants.php \Drupal\rng\Element\Registrants::validateIdentityElement()
- 3.x src/Element/Registrants.php \Drupal\rng\Element\Registrants::validateIdentityElement()
Generic validator for the element.
File
- src/
Element/ Registrants.php, line 613
Class
- Registrants
- Provides a form element for a registrant and person association.
Namespace
Drupal\rng\ElementCode
public static function validateIdentityElement(&$element, FormStateInterface $form_state, &$complete_form) {
$utility = new RegistrantsElement($element, $form_state);
$registrants = $element['#value'];
$arity_is_single = $utility
->getArity() === 'single';
if ($arity_is_single) {
$registrants = array_slice($registrants, 0, 1);
$change_it = $utility
->getChangeIt();
if ($change_it) {
// Ensure if the change it is TRUE and single form is open then throw
// error.
$form_state
->setError($element, t('You must select a person.'));
}
}
// Store original form submission in temporary values.
$values = $form_state
->getValue($element['#parents']);
$form_state
->setTemporaryValue(array_merge([
'_registrants_values',
], $element['#parents']), $values);
// Change element value to registrant entities.
$form_state
->setValueForElement($element, $registrants);
}