You are here

RegistrantForm.php in RNG - Events and Registrations 3.x

File

src/Form/Entity/RegistrantForm.php
View source
<?php

namespace Drupal\rng\Form\Entity;

use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\rng\Entity\RegistrantInterface;
use Drupal\rng\Exception\InvalidEventException;
use Drupal\rng\Form\RegistrantFields;
use Drupal\rng\RegistrantsElementUtility;
use Drupal\user\Entity\User;

/**
 * Form controller for registrants.
 */
class RegistrantForm extends ContentEntityForm {

  /**
   * {@inheritdoc}
   */
  public function form(array $form, FormStateInterface $form_state, RegistrantInterface $registrant = NULL) {
    $registrant = $this->entity;

    /** @var RegistrantFields $helper */
    $helper = new RegistrantFields($form, $form_state, $registrant);
    $form = $helper
      ->getFields($form, $form_state, $registrant);
    return $form;
  }
  public function validateForm(array &$form, FormStateInterface $form_state) {
    RegistrantFields::validateForm($form, $form_state);
    return parent::validateForm($form, $form_state);
  }
  protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {

    //$form['#parents'][] = 'details';
    parent::copyFormValuesToEntity($entity, $form, $form_state);

    // TODO: Change the autogenerated stub
  }

  /**
   * {@inheritdoc}
   */
  public function save(array $form, FormStateInterface $form_state) {
    $registrant = $this->entity;
    $is_new = $registrant
      ->isNew();
    $registrant
      ->save();
    if ($is_new) {
      $this
        ->messenger()
        ->addMessage($this
        ->t('Registrant created.'));
    }
    else {
      $this
        ->messenger()
        ->addMessage($this
        ->t('Registrant updated.'));
    }
  }

  /**
   * @param array $form
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *
   * @return array|null
   */
  public static function ajaxRegistrantType(array $form, FormStateInterface $form_state) {
    return RegistrantsElementUtility::findElement($form, $form_state);
  }

}

Classes

Namesort descending Description
RegistrantForm Form controller for registrants.