You are here

function template_preprocess_views_foundation_clearing in Views Foundation 7

Same name and namespace in other branches
  1. 7.4 theme/views_foundation.theme.inc \template_preprocess_views_foundation_clearing()

Theme the Foundation Orbit Clearing.

File

theme/views_foundation.theme.inc, line 55
The theme system, which controls the output of views foundation plugins.

Code

function template_preprocess_views_foundation_clearing(&$variables) {

  // Preprare fields for the output.
  foreach ($variables['view']->style_plugin->rendered_fields as $index => $row) {
    foreach ($row as $key => $value) {
      if ($variables['options']['image'] == $key) {

        // Get image url from img tag.
        if ($value) {
          $url = simplexml_import_dom(DOMDocument::loadHTML($value))
            ->xpath("//img/@src");
          $variables['fields'][$index]['image'] = check_url(reset($url));
        }
      }
      elseif ($variables['options']['thumbnail'] == $key) {

        // Get thumbnail url from img tag.
        if ($value) {
          $url = simplexml_import_dom(DOMDocument::loadHTML($value))
            ->xpath("//img/@src");
          $variables['fields'][$index]['thumbnail'] = check_url(reset($url));
        }
      }
      elseif ($variables['options']['caption'] == $key) {
        $value ? $variables['fields'][$index]['caption'] = check_plain(strip_tags($value)) : '';
      }
    }
    if (!isset($variables['fields'][$index]['image'])) {

      // Unset row if main image not found.
      unset($variables['fields'][$index]);
    }
    elseif (!isset($variables['fields'][$index]['thumbnail'])) {

      // Use main image for thumbnail if thumbnail not set.
      $variables['fields'][$index]['thumbnail'] = $variables['fields'][$index]['image'];
    }
  }

  // Add classes for grid and thumbnail border.
  $grid = drupal_html_class($variables['options']['thumb_columns']);
  $mobile_grid = drupal_html_class($variables['options']['thumb_columns_mobile']);
  $variables['class']['link'] = $variables['options']['thumb_border'] ? 'clearing-link th' : 'clearing-link';
  $variables['class']['grid'] = 'clearing block-grid ' . $grid . '-up mobile-' . $mobile_grid . '-up';

  // Add Foundation Clearing JavaScript.
  drupal_add_js(check_url(variable_get('views_foundation_js')) . '/jquery.foundation.clearing.js');
}