function theme_isotope_grid in Brainstorm profile 7
Default theme implementation for the grid.
Parameters
array $vars: Variables for theming.
Return value
string Markup.
2 theme calls to theme_isotope_grid()
- template_preprocess_views_isotope_views_grid in modules/
custom/ views_isotope/ views/ views_isotope_views.theme.inc - Preprocess function to build the isotope grid.
- views_isotope_example_theme_page in modules/
custom/ views_isotope/ views_isotope_example/ views_isotope_example.module - Page callback.
File
- modules/
custom/ views_isotope/ views_isotope.module, line 385 - Load the isotope library and provide configuration and theme options.
Code
function theme_isotope_grid(array $vars) {
// A config name specified in context will override whatever we have been
// passed.
$config_name = $vars['config'];
if (module_exists('context')) {
if ($plugin = context_get_plugin('reaction', 'isotope')) {
$context_name = $plugin
->execute();
if (!empty($context_name)) {
$config_name = $context_name;
}
}
}
// Add the sorting options to the initial configuration.
$additional_config = [
'getSortData' => [],
];
foreach ($vars['items'] as $item) {
$item['data'] = !empty($item['data']) ? $item['data'] : [];
foreach ($item['data'] as $key => $value) {
$additional_config['getSortData'][$key] = '.' . $key;
}
}
// Retrieve the desired configuration (plus sorting options).
$config = views_isotope_get_config_json($config_name, $additional_config);
// Make sure the instance name is unique per page load.
$global_instances =& drupal_static(__FUNCTION__);
$global_instances = isset($global_instances) ? $global_instances : [];
if (!empty($vars['instance']) && !in_array($vars['instance'], $global_instances)) {
$instance_name = $vars['instance'];
}
else {
for ($i = 0; $i >= 0; $i++) {
if (!in_array($i, $global_instances)) {
$instance_name = $i;
// Break the infinite loop when successful.
break;
}
}
}
$global_instances[] = $instance_name;
$instance = 'isotope-instance-' . $instance_name;
$items = [
[
'data' => '',
'class' => [
'isotope-grid-sizer',
],
],
[
'data' => '',
'class' => [
'isotope-gutter-sizer',
],
],
];
foreach ($vars['items'] as $item) {
$sorts = '';
$item['data'] = !empty($item['data']) ? $item['data'] : [];
foreach ($item['data'] as $key => $value) {
if (!is_array($value)) {
$value = [
$value,
];
}
foreach ($value as $sort) {
$sorts .= '<div class="sort-data ' . $key . '">' . views_isotope_sanitize($sort) . '</div>';
}
$item['data'][$key] = views_isotope_sanitize($value);
}
$classes = array_values($item['data']);
$classes[] = 'isotope-element';
$items[] = [
'data' => $item['value'] . $sorts,
'class' => $classes,
];
}
$return = [
'#theme' => 'item_list',
'#items' => $items,
'#type' => 'ul',
'#attributes' => [
'class' => 'isotope-container js-isotope',
'id' => $instance,
'data-isotope-options' => $config,
],
'#attached' => [
'js' => [
drupal_get_path('module', 'views_isotope') . '/views_isotope.js',
],
'css' => [
drupal_get_path('module', 'views_isotope') . '/views_isotope.css',
],
],
];
views_isotope_addjs($config_name);
return drupal_render($return);
}