slick.module in Slick Carousel 8.2
Same filename and directory in other branches
Slick carousel integration, the last carousel you'll ever need.
File
slick.moduleView source
<?php
/**
* @file
* Slick carousel integration, the last carousel you'll ever need.
*/
use Drupal\Component\Utility\NestedArray;
use Drupal\blazy\Blazy;
use Drupal\slick\SlickDefault;
/**
* Provides a convenient shortcut for procedural hooks.
*
* @param string $key
* Identifier of the service.
*
* @return class
* The required Slick class instance.
*/
function slick($key = 'manager') {
static $manager;
static $skin_manager;
if (!isset($manager)) {
$manager = \Drupal::service('slick.manager');
$skin_manager = \Drupal::service('slick.skin_manager');
}
switch ($key) {
case 'skin':
return $skin_manager;
default:
return $manager;
}
}
/**
* Implements hook_theme().
*/
function slick_theme() {
$themes = [];
$items = [
'slick',
'slide',
'grid',
'thumbnail',
'vanilla',
'wrapper',
];
foreach ($items as $item) {
$key = $item == 'slick' ? $item : 'slick_' . $item;
$themes[$key] = [
'render element' => 'element',
'file' => 'templates/slick.theme.inc',
];
}
return $themes;
}
/**
* Implements hook_library_info_build().
*/
function slick_library_info_build() {
return slick('skin')
->libraryInfoBuild();
}
/**
* Implements hook_config_schema_info_alter().
*
* @todo replace with BlazyAlter::configSchemaInfoAlter() post blazy:8.x-2.0.
*/
function slick_config_schema_info_alter(array &$definitions) {
Blazy::configSchemaInfoAlter($definitions, 'slick_base', SlickDefault::extendedSettings());
}
/**
* Implements hook_library_info_alter().
*/
function slick_library_info_alter(&$libraries, $extension) {
if ($extension === 'slick') {
slick('skin')
->libraryInfoAlter($libraries, $extension);
}
}
/**
* Provides a wrapper to replace deprecated libraries_get_path() at ease.
*
* @todo remove and replace with blazy_libraries_get_path() post blazy:8.x-2.0.
*/
function slick_libraries_get_path($name, $base_path = FALSE) {
$function = 'libraries_get_path';
if (\Drupal::hasService('library.libraries_directory_file_finder')) {
return \Drupal::service('library.libraries_directory_file_finder')
->find($name);
}
elseif (is_callable($function)) {
return $function($name, $base_path);
}
return FALSE;
}
/**
* Implements hook_page_attachments().
*/
function slick_page_attachments(array &$attachments) {
$sitewide = slick()
->configLoad('sitewide', 'slick.settings');
if (!empty($sitewide) && $sitewide > 0 && !\Drupal::service('router.admin_context')
->isAdminRoute()) {
$slicks = slick()
->attach([
'_unload' => $sitewide == 2 || $sitewide == 3,
'_vanilla' => $sitewide == 2,
]);
$attachments['#attached'] = empty($attachments['#attached']) ? $slicks : NestedArray::mergeDeep($slicks, $attachments['#attached']);
}
}
/**
* Implements hook_hook_info().
*
* @todo deprecate and remove post slick: 3.x, or 9.x, not 2.x, for BC.
*/
function slick_hook_info() {
$hooks['slick_skins_info'] = [
'group' => 'slick',
];
return $hooks;
}
/**
* Implements hook_field_formatter_info_alter().
*
* @todo deprecated in blazy:8.x-2.0 and is removed from blazy:8.x-3.0. Use
* \Drupal\slick\Plugin\Field\FieldFormatter\SlickMediaFormatter instead.
* @see https://www.drupal.org/node/3103018
*/
function slick_field_formatter_info_alter(array &$info) {
// Supports Media Entity via VEM within VEF if available.
if (slick()
->getModuleHandler()
->moduleExists('video_embed_media')) {
$info['slick_file'] = [
'id' => 'slick_file',
'label' => t('Slick Image with VEF (deprecated)'),
'description' => t('Display the images associated to VEM/ME as a simple mix of Slick image/video carousel.'),
'class' => 'Drupal\\slick\\Plugin\\Field\\FieldFormatter\\SlickFileFormatter',
'field_types' => [
'entity_reference',
'image',
],
'quickedit' => [
'editor' => 'disabled',
],
'provider' => 'slick',
];
}
}
Functions
Name | Description |
---|---|
slick | Provides a convenient shortcut for procedural hooks. |
slick_config_schema_info_alter | Implements hook_config_schema_info_alter(). |
slick_field_formatter_info_alter | Implements hook_field_formatter_info_alter(). |
slick_hook_info | Implements hook_hook_info(). |
slick_libraries_get_path | Provides a wrapper to replace deprecated libraries_get_path() at ease. |
slick_library_info_alter | Implements hook_library_info_alter(). |
slick_library_info_build | Implements hook_library_info_build(). |
slick_page_attachments | Implements hook_page_attachments(). |
slick_theme | Implements hook_theme(). |