You are here

function theme_isotope_grid in Views Isotope (Deprecated) 7.2

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 views/views_isotope_views.theme.inc
Preprocess function to build the isotope grid.
views_isotope_example_theme_page in views_isotope_example/views_isotope_example.module
Page callback.

File

./views_isotope.module, line 384
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 = array(
    'getSortData' => array(),
  );
  foreach ($vars['items'] as $item) {
    $item['data'] = !empty($item['data']) ? $item['data'] : array();
    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 : array();
  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 = array(
    array(
      'data' => '',
      'class' => array(
        'isotope-grid-sizer',
      ),
    ),
    array(
      'data' => '',
      'class' => array(
        'isotope-gutter-sizer',
      ),
    ),
  );
  foreach ($vars['items'] as $item) {
    $sorts = '';
    $item['data'] = !empty($item['data']) ? $item['data'] : array();
    foreach ($item['data'] as $key => $value) {
      if (!is_array($value)) {
        $value = array(
          $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[] = array(
      'data' => $item['value'] . $sorts,
      'class' => $classes,
    );
  }
  $return = array(
    '#theme' => 'item_list',
    '#items' => $items,
    '#type' => 'ul',
    '#attributes' => array(
      'class' => 'isotope-container js-isotope',
      'id' => $instance,
      'data-isotope-options' => $config,
    ),
    '#attached' => array(
      'js' => array(
        drupal_get_path('module', 'views_isotope') . '/views_isotope.js',
      ),
      'css' => array(
        drupal_get_path('module', 'views_isotope') . '/views_isotope.css',
      ),
    ),
  );
  views_isotope_addjs($config_name);
  return drupal_render($return);
}