public function Attachment::attach in jQuery World Calendars API 3.x
@todo: Add validation API for component availability.
Parameters
array $page:
$components: Library components that should be loaded on the page. Either a string with a single filename or comma-separated filenames. Also it accepts an array of filenames. Allowed values are:
- all: contains base, plus and datepicker components together.
- core
- plus
- picker
- picker.ext
- validation
$types:
- taiwan
- thai
- julian
- persian
- islamic
- hebrew
- ethiopian
- coptic
- mayan
- ...
$locales: Library localization files that should be loaded on the page. This can be an array, a single string or a comma-separated one. Note that compressions for these components are not available. If passed empty automatically adds the languages that are enabled in site Allowed values are:
- lang: contains all Gregorian calendar locales.
- picker.lang: contains all datepicker locales.
- taiwan-zh-TW
- thai-th
- persian-fa
- islamic-ar
- hebrew-he
- ethiopian-am
- gregorian-af
- gregorian-sq
- picker-af
- picker-sq
- picker-fa
- ...
$theme: Datepicker theme.
$compression: Compression level:
- normal
- min
- pack
Overrides ElementAttachmentInterface::attach
See also
http://keith-wood.name/calendars.html
http://keith-wood.name/calendarsPicker.html
File
- src/
Attachment.php, line 114
Class
- Attachment
- An implementation of PageAttachmentInterface for the library.
Namespace
Drupal\jquery_calendarCode
public function attach(array &$page, $components = [], $types = [], $locales = [], $theme = NULL, $compression = NULL) {
// Add current lang to drupal js settings to be used by date pickers on runtime when necessary
$language = \Drupal::languageManager()
->getCurrentLanguage();
$lang = $language
->getId();
$compression = !empty($compression) ? $compression : \Drupal::config('jquery_calendar.settings')
->get('compression_level');
$theme = !empty($theme) ? $theme : \Drupal::config('jquery_calendar.settings')
->get('datepicker_theme');
$js_settings = [
'lang' => $lang,
];
foreach ($components as $component) {
$page['#attached']['library'][] = 'jquery_calendar/jquery_calendars.' . $component;
}
foreach ($types as $type) {
if ($type === 'gregorian') {
continue;
}
$page['#attached']['library'][] = 'jquery_calendar/jquery_calendars.type.' . $type;
}
foreach ($locales as $local) {
if ($local === 'en') {
continue;
}
foreach ($components as $component) {
$page['#attached']['library'][] = 'jquery_calendar/jquery_calendars.lang.' . $component . '-' . $local;
}
foreach ($types as $type) {
$page['#attached']['library'][] = 'jquery_calendar/jquery_calendars.lang.type.' . $type . '-' . $local;
}
}
if ($theme) {
$page['#attached']['library'][] = 'jquery_calendar/jquery_calendars.picker.theme.' . $theme;
}
// Give other modules the possibility to override settings
$this->moduleHandler
->alter('jquery_calendar_settings', $js_settings, $style);
// Add js settings.
$page['#attached']['drupalSettings']['jquery_calendar'] = $js_settings;
}