public function RegistrationTypeForm::buildForm in RNG - Events and Registrations 3.x
Same name and namespace in other branches
- 8.2 src/Form/RegistrationTypeForm.php \Drupal\rng\Form\RegistrationTypeForm::buildForm()
- 8 src/Form/RegistrationTypeForm.php \Drupal\rng\Form\RegistrationTypeForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides EntityForm::buildForm
File
- src/
Form/ RegistrationTypeForm.php, line 37
Class
- RegistrationTypeForm
- Form controller for registration types.
Namespace
Drupal\rng\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$registration_type = $this->entity;
if (!$registration_type
->isNew()) {
$form['#title'] = $this
->t('Edit registration type %label', [
'%label' => $registration_type
->label(),
]);
}
// Build the form.
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#maxlength' => 255,
'#default_value' => $registration_type
->label(),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#title' => $this
->t('Machine name'),
'#default_value' => $registration_type
->id(),
'#machine_name' => [
'exists' => [
$this,
'exists',
],
'replace_pattern' => '([^a-z0-9_]+)|(^custom$)',
'error' => 'The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores.',
],
'#disabled' => !$registration_type
->isNew(),
];
$form['description'] = [
'#type' => 'textarea',
'#title' => t('Description'),
'#default_value' => $registration_type->description,
'#description' => t('Description will be displayed when a user is choosing which registration type to use for an event.'),
];
return $form;
}