public function EditRepeatingRuleConfirmationModalForm::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_event_series/ src/ Form/ EditRepeatingRuleConfirmationModalForm.php, line 86 - Contains \Drupal\bat_event_series\Form\EditRepeatingRuleConfirmationModalForm.
Class
Namespace
Drupal\bat_event_series\FormCode
public function buildForm(array $form, FormStateInterface $form_state, EventSeries $bat_event_series = NULL) {
$this->event_series = $bat_event_series;
$values = $this->tempStore
->get($this
->currentUser()
->id());
$events = $this
->getEvents(new \DateTime($values['start_date']), new \DateTime($values['end_date']), $values['repeat_frequency'], $values['repeat_until']);
if (!empty($events['delete_events'])) {
$form['delete_events'] = [
'#type' => 'details',
'#title' => $this
->t('Events to delete'),
'#description' => $this
->t('The following events will be deleted.'),
'#open' => TRUE,
];
$form['delete_events'][] = [
'#theme' => 'item_list',
'#items' => $events['delete_events'],
];
}
if (!empty($events['add_events'])) {
$form['add_events'] = [
'#type' => 'details',
'#title' => $this
->t('Events to add'),
'#description' => t('The following events will be added.'),
'#open' => TRUE,
];
$form['add_events'][] = [
'#theme' => 'item_list',
'#items' => $events['add_events'],
];
}
if (!empty($events['not_available_events'])) {
$form['not_available_events'] = [
'#type' => 'details',
'#title' => $this
->t('Events not available'),
'#description' => t('The following events are not available and will not be added.'),
'#open' => TRUE,
];
$form['not_available_events'][] = [
'#theme' => 'item_list',
'#items' => $events['not_available_events'],
];
}
$form['events'] = [
'#type' => 'value',
'#value' => $events,
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Continue'),
'#attributes' => [
'class' => [
'button--primary',
],
],
'#ajax' => [
'callback' => [
$this,
'ajaxSubmit',
],
'url' => Url::fromRoute('entity.bat_event_series.edit_confirmation_form_modal', [
'bat_event_series' => $bat_event_series
->id(),
]),
'options' => [
'query' => [
FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
],
],
],
];
if (empty($events['delete_events']) && empty($events['add_events']) && empty($events['not_available_events'])) {
$form['no_events'] = [
'#markup' => $this
->t('No events will be created or deleted'),
];
unset($form['actions']['submit']['#ajax']);
$form['actions']['submit']['#attributes']['class'][] = 'dialog-cancel';
}
$form['actions']['cancel'] = [
'#type' => 'submit',
'#value' => $this
->t('Cancel'),
'#attributes' => [
'class' => [
'button--danger',
'dialog-cancel',
],
],
];
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
return $form;
}