You are here

public static function RegistrantFields::removeIdentity in RNG - Events and Registrations 3.x

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

File

src/Form/RegistrantFields.php, line 216

Class

RegistrantFields
Class RegistrantFields

Namespace

Drupal\rng\Form

Code

public static function removeIdentity(array $form, FormStateInterface $form_state) {
  $trigger = $form_state
    ->getTriggeringElement();
  $parents = $trigger['#array_parents'];

  // Trim off last two elements - identity_types, remove_element
  array_pop($parents);
  array_pop($parents);
  $element = NestedArray::getValue($form, $parents);

  /** @var RegistrantInterface $registrant */
  $registrant = reset($element['#value']);
  $registrant
    ->clearIdentity();
  $event_type = $registrant
    ->getRegistration()
    ->getEventMeta()
    ->getEventType();
  if ($event_type
    ->getAutoAttachUsers()) {
    $email_field = $event_type
      ->getRegistrantEmailField();
    $registrant
      ->set($email_field, null);
  }
}