function template_preprocess_uikit_view_grid in UIkit Components 8.3
Same name and namespace in other branches
- 8 uikit_views/includes/uikit_views.theme.inc \template_preprocess_uikit_view_grid()
- 8.2 uikit_views/includes/uikit_views.theme.inc \template_preprocess_uikit_view_grid()
- 7.3 uikit_views/templates/uikit_views.theme.inc \template_preprocess_uikit_view_grid()
- 7.2 uikit_views/templates/uikit_views.theme.inc \template_preprocess_uikit_view_grid()
Prepares variables for UIkit Grid templates.
Default template: uikit-view-grid.html.twig.
Parameters
array $variables: An associative array containing:
- view: A ViewExecutable object.
- rows: The raw row data.
1 string reference to 'template_preprocess_uikit_view_grid'
- UIkitViews::getThemeHooks in uikit_views/
src/ UIkitViews.php - Returns the theme hook definition information for UIkit Views.
File
- uikit_views/
includes/ uikit_views.theme.inc, line 67 - Preprocessors and helper functions to make theming easier.
Code
function template_preprocess_uikit_view_grid(array &$variables) {
$view = $variables['view'];
$options = $view->style_plugin->options;
$grid_attributes = new Attribute();
$variables['id'] = UIkitViews::getUniqueId($view);
if ($options['grid_lightbox'] == TRUE) {
$grid_attributes
->setAttribute('data-uk-lightbox', 'true');
}
$grid_attributes
->setAttribute('data-uk-grid', '');
$grid_attributes
->setAttribute('class', 'uk-grid');
if ($options['grid_behavior'] == 'masonry') {
$grid_attributes
->setAttribute('data-uk-grid', 'masonry: true');
}
$grid_classes = [];
if ($options['grid_behavior'] == 'match' && $options['grid_match_height_selector'] == NULL) {
$grid_classes[] = 'uk-grid-match';
}
if ($options['grid_behavior'] == 'match' && $options['grid_match_height_selector'] != NULL) {
$grid_attributes
->setAttribute('data-uk-height-match', 'target: ' . $options['grid_match_height_selector']);
}
if ($options['flex_classes'] != NULL) {
$grid_classes += explode(' ', $options['flex_classes']);
}
if ($options['grid_gutter'] != 'default') {
$grid_classes[] = $options['grid_gutter'];
}
if ($options['grid_divider'] == TRUE) {
$grid_classes[] = 'uk-grid-divider';
}
foreach ([
'',
'@s',
'@m',
'@l',
'@xl',
] as $size) {
$grid_classes[] = $options["width_" . $size];
}
$grid_attributes
->addClass($grid_classes);
$variables['grid_attributes'] = $grid_attributes;
$variables['options'] = $options;
$items = [];
// Iterate over each rendered views result row.
foreach ($variables['rows'] as $result_index => $item) {
$items[$result_index]['content'] = $item;
}
// Add items to the variables array.
$variables['items'] = $items;
}