You are here

public static function RegistrantFields::validateForm in RNG - Events and Registrations 8.2

Same name and namespace in other branches
  1. 3.x src/Form/RegistrantFields.php \Drupal\rng\Form\RegistrantFields::validateForm()

Attach an identity if selected in subform.

Parameters

array $form:

\Drupal\Core\Form\FormStateInterface $form_state:

1 call to RegistrantFields::validateForm()
RegistrantForm::validateForm in src/Form/Entity/RegistrantForm.php
Button-level validation handlers are highly discouraged for entity forms, as they will prevent entity validation from running. If the entity is going to be saved during the form submission, this method should be manually invoked from the button-level…

File

src/Form/RegistrantFields.php, line 193

Class

RegistrantFields
Class RegistrantFields

Namespace

Drupal\rng\Form

Code

public static function validateForm(array &$form, FormStateInterface $form_state) {

  /** @var RegistrantInterface $registrant */
  $registrant = reset($form['#value']);
  $types = $form_state
    ->getValue(array_merge($form['#parents'], [
    'identity_types',
  ]));
  if (!empty($types)) {
    switch ($types) {
      case 'myself:':
        $account = User::load(\Drupal::currentUser()
          ->id());
        $registrant
          ->setIdentity($account);
        break;
    }
  }
  $parents = array_merge($form['#parents'], [
    'details',
  ]);
  $values = $form_state
    ->getValue($parents);
  if (!empty($values)) {
    foreach ($values as $name => $value) {
      if ($registrant
        ->hasField($name)) {
        $registrant
          ->set($name, $value);
      }
    }
  }
}