You are here

public static function Registrants::submitExisting in RNG - Events and Registrations 8

Same name and namespace in other branches
  1. 8.2 src/Element/Registrants.php \Drupal\rng\Element\Registrants::submitExisting()
  2. 3.x src/Element/Registrants.php \Drupal\rng\Element\Registrants::submitExisting()

Submission callback for existing entities.

Parameters

array $form: The complete form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

File

src/Element/Registrants.php, line 928

Class

Registrants
Provides a form element for a registrant and person association.

Namespace

Drupal\rng\Element

Code

public static function submitExisting(array $form, FormStateInterface $form_state) {
  $form_state
    ->setRebuild();
  $element = RegistrantsElement::findElement($form, $form_state);
  $utility = new RegistrantsElement($element, $form_state);
  $registrant = $utility
    ->buildRegistrant();
  $utility
    ->clearPeopleFormInput();
  $autocomplete_tree = array_merge($element['#parents'], [
    'entities',
    'person',
    'existing',
    'existing_autocomplete',
  ]);
  $existing_value = NestedArray::getValue($form_state
    ->getTemporaryValue('_registrants_values'), $autocomplete_tree);
  $subform_autocomplete = NestedArray::getValue($form, $autocomplete_tree);
  $existing_entity_type = $subform_autocomplete['#target_type'];
  $person = \Drupal::entityTypeManager()
    ->getStorage($existing_entity_type)
    ->load($existing_value);
  $registrant
    ->setIdentity($person);
  $arity = $utility
    ->getArity();
  if ($arity === 'single') {
    $utility
      ->replaceFirstRegistrant($registrant);
    $utility
      ->setChangeIt(FALSE);
  }
  else {
    $utility
      ->addRegistrant($registrant);
  }
}