You are here

public function BatEventUiBulkUpdateForm::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_ui/src/Form/BatEventUiBulkUpdateForm.php, line 28
Contains \Drupal\bat_event_ui\Form\BatEventUiBulkUpdateForm.

Class

BatEventUiBulkUpdateForm

Namespace

Drupal\bat_event_ui\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $unit_type = 'all', $event_type = 'all') {
  $form['bulk_update'] = [
    '#type' => 'fieldset',
    '#title' => t('Update event state'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  ];
  $form['bulk_update']['event_type'] = [
    '#type' => 'hidden',
    '#value' => $event_type,
  ];
  if ($unit_type == 'all') {
    $types = bat_unit_get_types();
    $types_options = [];
    foreach ($types as $type) {
      $type_bundle = bat_type_bundle_load($type
        ->bundle());
      if (is_array($type_bundle->default_event_value_field_ids)) {
        if (isset($type_bundle->default_event_value_field_ids[$event_type]) && !empty($type_bundle->default_event_value_field_ids[$event_type])) {
          $types_options[$type
            ->id()] = $type
            ->label();
        }
      }
    }
    $form['bulk_update']['type'] = [
      '#type' => 'select',
      '#title' => t('Type'),
      '#options' => $types_options,
      '#required' => TRUE,
    ];
  }
  else {
    $form['bulk_update']['type'] = [
      '#type' => 'hidden',
      '#value' => $unit_type,
    ];
  }
  $form['bulk_update'] += bat_date_range_fields();
  $form['bulk_update']['state'] = [
    '#type' => 'select',
    '#title' => t('State'),
    '#options' => bat_unit_state_options($event_type, [
      'blocking' => 0,
    ]),
    '#required' => TRUE,
  ];
  $form['bulk_update']['submit'] = [
    '#type' => 'submit',
    '#value' => t('Update'),
  ];
  return $form;
}