You are here

public function Demo::buildForm in jQuery World Calendars API 3.x

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

src/Form/Demo.php, line 33
Contains \Drupal\jquery_calendar\Form\Demo.

Class

Demo

Namespace

Drupal\jquery_calendar\Form

Code

public function buildForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
  try {
    jquery_calendar_requirements_check(null);
  } catch (MissingRequirements $e) {
    \Drupal::messenger()
      ->addMessage(Markup::create($e
      ->getMessage() . ' ' . $this
      ->t('Checkout the <a href="@link">status reports</a>.', [
      '@link' => Url::fromRoute('system.status')
        ->toString(),
    ])), \Drupal::messenger()::TYPE_ERROR);
    return [];
  }

  // Calendar select widget:
  $form['datepicker_demo_wrapper']['demo'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Calendar'),
    '#description' => $this
      ->t('Choose the demonstration calendar system.'),
    '#default_value' => 'gregorian',
    '#attributes' => [
      'id' => 'datepicker-demo-calendars',
    ],
    '#options' => jquery_calendar_types('capital'),
  ];
  $form['datepicker_demo_wrapper']['lang'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Calendar Language'),
    '#description' => $this
      ->t('Choose the calendar language.'),
    '#default_value' => '',
    '#attributes' => [
      'id' => 'datepicker-demo-calendars-lang',
    ],
    '#options' => jquery_calendar_langs('flat'),
    '#suffix' => '<div id="datepicker-lang"></div>',
  ];
  $form['datepicker_demo_wrapper']['popup'] = [
    '#type' => 'textfield',
    '#size' => 40,
    '#default_value' => '',
    '#title' => $this
      ->t('Popup Calendar'),
    '#attributes' => [
      'class' => [
        'calendar_systems_js_date_picker_regular',
      ],
    ],
    '#suffix' => '<div id="datepicker-demo"></div>',
  ];
  \Drupal::service('jquery_calendar.attachment')
    ->attach($form['datepicker_demo_wrapper']['popup'], [
    'core',
    'plus',
    'picker',
    'picker.ext',
    'validation',
  ], array_keys(jquery_calendar_types()), array_keys(jquery_calendar_langs()));
  $form['datepicker_demo_wrapper']['#attached']['library'][] = 'jquery_calendar/demo';
  return $form;
}