You are here

public function EventSeriesTypeForm::form in Booking and Availability Management Tools for Drupal 8

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

modules/bat_event_series/src/EventSeriesTypeForm.php, line 51
Contains \Drupal\bat_event_series\EventSeriesTypeForm.

Class

EventSeriesTypeForm
Form handler for event series type forms.

Namespace

Drupal\bat_event_series

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $event_series_type = $this->entity;
  $form['name'] = [
    '#title' => t('Label'),
    '#type' => 'textfield',
    '#default_value' => $event_series_type
      ->label(),
    '#description' => t('The human-readable name of this event series type.'),
    '#required' => TRUE,
    '#size' => 30,
  ];
  $form['type'] = [
    '#type' => 'machine_name',
    '#default_value' => $event_series_type
      ->id(),
    '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
    '#disabled' => FALSE,
    '#machine_name' => [
      'exists' => [
        'Drupal\\bat_event_series\\Entity\\EventSeriesType',
        'load',
      ],
      'source' => [
        'name',
      ],
    ],
    '#description' => t('A unique machine-readable name for this event series type. It must only contain lowercase letters, numbers, and underscores.'),
  ];
  $form['event_granularity'] = [
    '#type' => 'select',
    '#title' => t('Event Granularity'),
    '#options' => [
      'bat_daily' => t('Daily'),
      'bat_hourly' => t('Hourly'),
    ],
    '#default_value' => !empty($event_series_type
      ->getEventGranularity()) ? $event_series_type
      ->getEventGranularity() : 'bat_daily',
  ];
  $options = [];
  foreach (bat_event_get_types() as $id => $event_type) {
    $options[$id] = $event_type
      ->label();
  }
  $form['target_event_type'] = [
    '#type' => 'select',
    '#title' => t('Target Event Type'),
    '#options' => $options,
    '#default_value' => $event_series_type
      ->getTargetEventType(),
  ];
  return $this
    ->protectBundleIdElement($form);
}