RegistrantForm.php in RNG - Events and Registrations 8.2
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;
class RegistrantForm extends ContentEntityForm {
public function form(array $form, FormStateInterface $form_state, RegistrantInterface $registrant = NULL) {
$registrant = $this->entity;
$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) {
parent::copyFormValuesToEntity($entity, $form, $form_state);
}
public function save(array $form, FormStateInterface $form_state) {
$registrant = $this->entity;
$is_new = $registrant
->isNew();
$registrant
->save();
if ($is_new) {
drupal_set_message($this
->t('Registrant created.'));
}
else {
drupal_set_message($this
->t('Registrant updated.'));
}
}
public static function ajaxRegistrantType(array $form, FormStateInterface $form_state) {
return RegistrantsElementUtility::findElement($form, $form_state);
}
}