-
Notifications
You must be signed in to change notification settings - Fork 1
/
isotope_views.module
46 lines (38 loc) · 1.45 KB
/
isotope_views.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/**
* @file
* A light-weight, customizable lightbox plugin for jQuery 1.3
*/
use Drupal\Core\Template\Attribute;
use Drupal\Component\Serialization\Json;
use Drupal\file\Entity\File;
use Drupal\image\Entity\ImageStyle;
/**
* Prepares variables for Views isotope templates.
*
* Default template: views-view-isotope.html.twig.
*
* @param array $variables
* An associative array containing:
* - view: A View object.
*/
function template_preprocess_views_view_isotope(&$variables) {
/** @var \Drupal\isotope_views\Plugin\views\style\Isotope $handler */
$handler = $variables['view']->style_plugin;
// Fetch wrapper classes from handler options.
$wrapper_classes = []; #['isotope-grid'];
if (!empty($handler->options['wrapper_class'])) {
$wrapper_classes = array_merge($wrapper_classes, explode(' ', $handler->options['wrapper_class']));
$wrapper_classes = array_map('\Drupal\Component\Utility\Html::cleanCssIdentifier', $wrapper_classes);
}
$variables['attributes'] = new Attribute(['class' => $wrapper_classes]);
$variables['attributes']['data-isotopesettings'] = Json::encode($handler->filterOptions());
$variables['#attached']['library'][] = 'isotope_views/isotope_views';
template_preprocess_views_view_unformatted($variables);
if ($handler->options['use_load_more']) {
// Hide rows initially.
foreach ($variables['rows'] as $id => $row) {
$variables['rows'][$id]['attributes']->addClass('hidden');
}
}
}