public function RegistrationForm::form in RNG - Events and Registrations 3.x
Same name and namespace in other branches
- 8.2 src/Form/RegistrationForm.php \Drupal\rng\Form\RegistrationForm::form()
- 8 src/Form/RegistrationForm.php \Drupal\rng\Form\RegistrationForm::form()
Gets the actual form array to be built.
Overrides ContentEntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
Form/ RegistrationForm.php, line 51
Class
- RegistrationForm
- Form controller for registrations.
Namespace
Drupal\rng\FormCode
public function form(array $form, FormStateInterface $form_state) {
/** @var \Drupal\rng\Entity\RegistrationInterface $registration */
$registration = $this
->getEntity();
$current_user = $this
->currentUser();
$event = $registration
->getEvent();
$event_meta = $this->eventManager
->getMeta($event);
$form = parent::form($form, $form_state);
if (!$registration
->isNew()) {
$form['#title'] = $this
->t('Edit Registration', [
'%event_label' => $event
->label(),
'%event_id' => $event
->id(),
'%registration_id' => $registration
->id(),
]);
}
// Registrants are initially either a collection of stub registrant
// entities, or a single blank one. After any data changes, registrants
// include all associated with the registration.
$registrants = $registration
->getRegistrants();
$form['registrants_before'] = [
'#type' => 'value',
'#value' => $registrants,
];
$form['people'] = [
'#type' => 'details',
'#title' => $this
->t('People'),
'#description' => $this
->t('Select people to associate with this registration.'),
'#open' => TRUE,
'#tree' => TRUE,
];
$event_type = $event_meta
->getEventType();
$form['people']['registrants'] = [
'#type' => 'registrants',
'#event' => $event,
'#default_value' => $registrants,
'#allow_creation' => $event_meta
->getCreatableIdentityTypes(),
'#allow_reference' => $event_meta
->getIdentityTypes(),
'#registration' => $registration,
'#form_modes' => $event_type
->getIdentityTypeEntityFormModes(),
'#tree' => TRUE,
];
if (!$registration
->isNew()) {
$form['revision_information'] = [
'#type' => 'details',
'#title' => $this
->t('Revisions'),
'#optional' => TRUE,
'#open' => $current_user
->hasPermission('administer rng'),
'#weight' => 20,
];
$form['revision'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Create new revision'),
'#description' => $this
->t('Revisions record changes between saves.'),
'#default_value' => FALSE,
'#access' => $current_user
->hasPermission('administer rng'),
'#group' => 'revision_information',
];
}
return $form;
}