You are here

function template_preprocess_ds_row_fields in Display Suite 7.2

Same name and namespace in other branches
  1. 6.3 theme/theme.inc \template_preprocess_ds_row_fields()
  2. 6 theme/theme.inc \template_preprocess_ds_row_fields()
  3. 6.2 theme/theme.inc \template_preprocess_ds_row_fields()
  4. 7 views/views_plugin_ds_fields_view.inc \template_preprocess_ds_row_fields()

Preprocess function for ds_fields_view().

File

views/views_plugin_ds_fields_view.inc, line 68
Provides the Display Suite views fields style plugin.

Code

function template_preprocess_ds_row_fields(&$vars) {
  static $row_layout = array();

  // Check if we have layout configured for this bundle.
  $bundle = $vars['view']->name . '-' . $vars['view']->current_display . '-fields';
  if (!isset($row_layout[$bundle])) {

    // Register the layout, even if when it returns false.
    $row_layout[$bundle] = ds_get_layout('ds_views', $bundle, 'default');

    // Add css.
    if ($row_layout[$bundle]) {
      drupal_add_css($row_layout[$bundle]['path'] . '/' . $row_layout[$bundle]['layout'] . '.css');
    }
  }

  // Render the views fields into the template layout.
  // This code is more or less copied from ds_entity_variables().
  if (isset($row_layout[$bundle])) {
    $view = $vars['view'];
    $layout = $row_layout[$bundle];
    if (!$layout) {
      return;
    }

    // Classes array.
    $vars['classes_array'] = array();
    $vars['classes_array'][] = strtr($bundle, '_', '-');

    // Template suggestions.
    $vars['theme_hook_suggestions'][] = $layout['layout'];
    $vars['theme_hook_suggestions'][] = $layout['layout'] . '__ds_views_' . $bundle;

    // Row index.
    $row_index = $view->row_index;

    // Layout wrapper.
    $vars['layout_wrapper'] = isset($layout['settings']['layout_wrapper']) ? $layout['settings']['layout_wrapper'] : 'div';

    // Layout attributes
    if (!empty($layout['settings']['layout_attributes'])) {
      $vars['layout_attributes'] = ' ' . $layout['settings']['layout_attributes'];
    }
    else {
      $vars['layout_attributes'] = '';
    }

    // Create region variables based on the layout settings.
    foreach ($layout['regions'] as $region_name => $region) {

      // Create the region content.
      $region_content = '';
      if (isset($layout['settings']['regions'][$region_name])) {
        foreach ($layout['settings']['regions'][$region_name] as $key => $field) {

          // Do not render the field when empty and configured to be hidden.
          if ($view->field[$field]->options['hide_empty'] && empty($view->style_plugin->rendered_fields[$row_index][$field])) {
            continue;
          }
          $region_content .= '<div class="views-field-' . $field . '">';
          if (!empty($view->field[$field]->options['label'])) {
            $region_content .= '<div class="field-label">';
            $region_content .= check_plain($view->field[$field]->options['label']);
            if ($view->field[$field]->options['element_label_colon']) {
              $region_content .= ':';
            }
            $region_content .= '</div>';
          }
          $region_content .= $view->style_plugin->rendered_fields[$row_index][$field];
          $region_content .= '</div>';
        }
      }
      $vars[$region_name] = $region_content;

      // Region wrapper.
      $vars[$region_name . '_wrapper'] = isset($layout['settings']['wrappers'][$region_name]) ? $layout['settings']['wrappers'][$region_name] : 'div';

      // Add extras classes to the region.
      $vars[$region_name . '_classes'] = !empty($layout['settings']['classes'][$region_name]) ? ' ' . implode(' ', $layout['settings']['classes'][$region_name]) : '';
    }
  }
}