You are here

public static function Registrants::submitCreate in RNG - Events and Registrations 3.x

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

Submission callback for creating new entities.

Parameters

array $form: The complete form.

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

Throws

\Drupal\Core\Entity\EntityStorageException

File

src/Element/Registrants.php, line 992

Class

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

Namespace

Drupal\rng\Element

Code

public static function submitCreate(array $form, FormStateInterface $form_state) {
  $form_state
    ->setRebuild();
  $element = RegistrantsElement::findElement($form, $form_state);
  $utility = new RegistrantsElement($element, $form_state);

  // New entity.
  $new_entity_tree = array_merge($element['#parents'], [
    'entities',
    'person',
    'new_person',
    'newentityform',
  ]);
  $subform_new_entity = NestedArray::getValue($form, $new_entity_tree);

  // Save the entity.

  /** @var \Drupal\Core\Entity\EntityInterface $new_person */
  $new_person = $form_state
    ->get('newentity__entity');
  $display = $form_state
    ->get('newentity__form_display');
  $value = $form_state
    ->getTemporaryValue(array_merge([
    '_registrants_values',
  ], $element['#parents']));
  $form_state
    ->setValue($element['#parents'], $value);
  $display
    ->extractFormValues($new_person, $subform_new_entity, $form_state);
  $new_person
    ->save();
  $utility
    ->addWhitelistExisting($new_person);
  $registrant = $utility
    ->buildRegistrant();
  $utility
    ->clearPeopleFormInput();
  $registrant
    ->setIdentity($new_person);
}