function template_preprocess_isotope_sorter in Isotope (with Masonry and Packery) 8
Prepares variables for isotope sorter template.
Parameters
array $variables: An associative array of variables.
File
- ./
isotope.theme.inc, line 169 - Preprocessors of isotope module.
Code
function template_preprocess_isotope_sorter(&$variables) {
$attributes['class'] = 'js-isotope-options js-sorts clearfix';
if (!empty($variables['instance'])) {
$attributes['data-instance-id'] = 'isotope-instance-' . $variables['instance'];
}
if (!empty($variables['default_label'])) {
$variables['sorts'] = [
$variables['default_label']
->__toString() => 'original-order',
] + $variables['sorts'];
}
$items = [];
foreach ($variables['sorts'] as $key => $value) {
$sort = is_array($value) ? implode(',', $value) : $value;
$label = empty($key) || is_numeric($key) ? $sort : $key;
$items[] = [
'#theme' => 'isotope_sorter_button',
'#value' => $sort,
'#label' => $label,
];
}
$variables['sorter'] = [
'#theme' => 'item_list',
'#items' => $items,
'#type' => 'ul',
'#title' => t('Sort By'),
'#attributes' => $attributes,
];
}