public static function SlickManager::slick in Slick Carousel 8
Same name and namespace in other branches
- 8.2 src/SlickManager.php \Drupal\slick\SlickManager::slick()
- 7.3 src/SlickManager.php \Drupal\slick\SlickManager::slick()
Returns a cacheable renderable array of a single slick instance.
Parameters
array $build: An associative array containing:
- items: An array of slick contents: text, image or media.
- options: An array of key:value pairs of custom JS overrides.
- optionset: The cached optionset object to avoid multiple invocations.
- settings: An array of key:value pairs of HTML/layout related settings.
Return value
array The cacheable renderable array of a slick instance, or empty array.
Overrides SlickManagerInterface::slick
1 call to SlickManager::slick()
File
- src/
SlickManager.php, line 203
Class
- SlickManager
- Implements BlazyManagerInterface, SlickManagerInterface.
Namespace
Drupal\slickCode
public static function slick(array $build = []) {
if (empty($build['items'])) {
return [];
}
foreach ([
'items',
'options',
'optionset',
'settings',
] as $key) {
$build[$key] = isset($build[$key]) ? $build[$key] : [];
}
$slick = [
'#theme' => 'slick',
'#items' => [],
'#build' => $build,
'#pre_render' => [
static::class . '::preRenderSlick',
],
];
$settings = $build['settings'];
if (isset($settings['cache'])) {
$suffixes[] = count($build['items']);
$suffixes[] = count(array_filter($settings));
$suffixes[] = $settings['cache'];
$cache['contexts'] = [
'languages',
];
$cache['max-age'] = $settings['cache'];
$cache['keys'] = isset($settings['cache_metadata']['keys']) ? $settings['cache_metadata']['keys'] : [
$settings['id'],
];
$cache['keys'][] = $settings['display'];
$cache['tags'] = Cache::buildTags('slick:' . $settings['id'], $suffixes, '.');
if (!empty($settings['cache_tags'])) {
$cache['tags'] = Cache::mergeTags($cache['tags'], $settings['cache_tags']);
}
$slick['#cache'] = $cache;
}
return $slick;
}