class Attachment in jQuery World Calendars API 3.x
An implementation of PageAttachmentInterface for the library.
Hierarchy
- class \Drupal\jquery_calendar\Attachment implements ElementAttachmentInterface uses StringTranslationTrait
Expanded class hierarchy of Attachment
1 string reference to 'Attachment'
1 service uses Attachment
File
- src/
Attachment.php, line 13
Namespace
Drupal\jquery_calendarView source
class Attachment implements ElementAttachmentInterface {
use StringTranslationTrait;
/**
* The service to determin if it should be activated.
*
* @var ActivationCheckInterface
*/
protected $activation;
/**
* The module handler.
*
* @var ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The settings.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $settings;
/**
* Create an instance of ColorboxAttachment.
*/
public function __construct(ActivationCheckInterface $activation, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config) {
$this->activation = $activation;
$this->moduleHandler = $module_handler;
$this->settings = $config
->get('jquery_calendar.settings');
}
/**
* {@inheritdoc}
*/
public function isApplicable() {
return !InstallerKernel::installationAttempted() && $this->activation
->isActive();
}
/**
* @param array $page
* @param $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
* @param $types
* - taiwan
* - thai
* - julian
* - persian
* - islamic
* - hebrew
* - ethiopian
* - coptic
* - mayan
* - ...
* @param $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
* - ...
* @param $theme
* Datepicker theme.
* @param $compression
* Compression level:
* - normal
* - min
* - pack
*
* @see http://keith-wood.name/calendars.html
* @see http://keith-wood.name/calendarsPicker.html
*
* @todo: Add validation API for component availability.
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Attachment:: |
protected | property | The service to determin if it should be activated. | |
Attachment:: |
protected | property | The module handler. | |
Attachment:: |
protected | property | The settings. | |
Attachment:: |
public | function |
@todo: Add validation API for component availability. Overrides ElementAttachmentInterface:: |
|
Attachment:: |
public | function |
Check if the attachment should be added to the current page. Overrides ElementAttachmentInterface:: |
|
Attachment:: |
public | function | Create an instance of ColorboxAttachment. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |