You are here

public function StateForm::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 EntityForm::buildForm

File

modules/bat_event/src/Entity/Form/StateForm.php, line 25
Contains \Drupal\bat_event\Entity\Form\StateForm.

Class

StateForm
Class StateForm.

Namespace

Drupal\bat_event\Entity\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);
  $state = $this->entity;
  $form['machine_name'] = [
    '#type' => 'machine_name',
    '#default_value' => $state
      ->getMachineName(),
    '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
    '#disabled' => FALSE,
    '#machine_name' => [
      'exists' => [
        'Drupal\\bat_event\\Entity\\State',
        'loadByMachineName',
      ],
      'source' => [
        'name',
        'widget',
        '0',
        'value',
      ],
    ],
    '#description' => t('A unique machine-readable name for this state. It must only contain lowercase letters, numbers, and underscores.'),
  ];
  $form['color'] = [
    '#type' => 'textfield',
    '#title' => t('Color'),
    '#size' => 12,
    '#maxlength' => 7,
    '#default_value' => $state
      ->getColor(),
    '#dependency' => [
      'edit-row-options-colors-legend' => [
        'type',
      ],
    ],
    '#prefix' => '<div class="bat-colorpicker-wrapper form-wrapper">',
    '#suffix' => '<div class="bat-colorpicker"></div></div>',
    '#attributes' => [
      'class' => [
        'bat-edit-colorpicker',
      ],
    ],
    '#attached' => [
      'library' => [
        'bat_event/color',
      ],
    ],
    '#required' => TRUE,
  ];
  $form['calendar_label'] = [
    '#type' => 'textfield',
    '#title' => t('Calendar label'),
    '#size' => 10,
    '#maxlength' => 50,
    '#default_value' => $state
      ->getCalendarLabel(),
    '#required' => TRUE,
  ];
  $form['blocking'] = [
    '#type' => 'checkbox',
    '#title' => t('Blocking'),
    '#default_value' => $state
      ->getBlocking(),
  ];
  if (!$state
    ->isNew() && $this->entity
    ->getEventType()) {
    $form['event_type']['#access'] = FALSE;
  }
  return $form;
}