public function UnitSetStateAction::buildForm in Booking and Availability Management Tools for Drupal 8
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 FormInterface::buildForm
File
- modules/
bat_unit/ src/ Form/ UnitSetStateAction.php, line 63 - Contains \Drupal\bat_unit\Form\UnitSetStateAction.
Class
Namespace
Drupal\bat_unit\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$this->unitInfo = $this->tempStoreFactory
->get('unit_set_state_action_form')
->get($this
->currentUser()
->id());
$values = $form_state
->getValues();
$event_types_options = [];
$event_types = bat_event_get_types();
foreach ($event_types as $event_type) {
if ($event_type
->getFixedEventStates()) {
$event_types_options[$event_type
->id()] = $event_type
->label();
}
}
$form += bat_date_range_fields();
$form['event_type'] = [
'#type' => 'select',
'#title' => t('Event type'),
'#options' => $event_types_options,
'#required' => TRUE,
'#ajax' => [
'callback' => '::eventTypeChange',
'wrapper' => 'event-state-wrapper',
],
];
if (isset($values['event_type'])) {
$state_options = [];
foreach (bat_event_get_states($values['event_type']) as $state) {
$state_options[$state
->getMachineName()] = $state
->label();
}
$form['event_state'] = [
'#type' => 'select',
'#title' => t('Event state'),
'#options' => $state_options,
'#required' => TRUE,
'#prefix' => '<div id="event-state-wrapper">',
'#suffix' => '</div>',
];
}
else {
$form['event_state'] = [
'#prefix' => '<div id="event-state-wrapper">',
'#suffix' => '</div>',
];
}
$form['submit'] = [
'#type' => 'submit',
'#value' => t('Apply'),
];
return $form;
}