View source
<?php
use Drupal\Core\Template\Attribute;
function template_preprocess_flickity(&$variables) {
$group = flickity_settings($variables['settings']);
$variables['#attached'] = array(
'drupalSettings' => array(
'flickity' => array(
$group['id'] => array(
'settings' => $group['settings'],
),
),
),
'library' => array(
'flickity/local',
'flickity/settings',
),
);
}
function theme_flickity($variables) {
$output = array(
'#output' => array(
'settings' => $variables['settings'],
'items' => $variables['items'],
),
'#pre_render' => array(
'flickity_pre_render_element',
),
);
return drupal_render($output);
}
function flickity_pre_render_element($element) {
$items = array();
foreach ($element['#output']['items'] as $key => $item) {
$items[] = array(
'#theme' => 'flickity_item',
'#item' => $item['row'],
'#attributes' => array(
'class' => array(
'gallery-cell',
'item-' . $key,
),
),
);
}
$build = flickity_build($element['#output']['settings'], $items);
\Drupal::moduleHandler()
->alter('pre_render', $build);
$element['#children'] = drupal_render($build);
return $element;
}
function template_preprocess_flickity_item(&$variables) {
$variables['attributes'] = new Attribute($variables['attributes']);
}
function flickity_build($group, $output) {
return array(
'#output' => $output,
'#attributes' => array(
'class' => array(
$group,
'flickity',
),
),
'#theme_wrappers' => array(
'flickity_wrapper',
),
);
}
function template_preprocess_flickity_wrapper(&$variables) {
$variables['attributes'] = new Attribute($variables['attributes']);
}