Demo.php in jQuery World Calendars API 3.x
Contains \Drupal\jquery_calendar\Form\Demo.
Namespace
Drupal\jquery_calendar\FormFile
src/Form/Demo.phpView source
<?php
/**
* @file
* Contains \Drupal\jquery_calendar\Form\Demo.
*/
namespace Drupal\jquery_calendar\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Render\Markup;
use Drupal\Core\Url;
use Drupal\jquery_calendar\Error\MissingRequirements;
class Demo extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'jquery_calendar_form_demo';
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
}
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;
}
}