You are here

function template_preprocess_views_view_mapping_test in Views (for Drupal 7) 7.3

Same name and namespace in other branches
  1. 8.3 tests/views_test_data/views_test_data.module \template_preprocess_views_view_mapping_test()

Implements hook_preprocess_HOOK() for theme_views_view_mapping_test().

File

tests/views_test.module, line 70
Helper module for Views tests.

Code

function template_preprocess_views_view_mapping_test(&$variables) {
  $variables['element'] = array();
  foreach ($variables['rows'] as $delta => $row) {
    $fields = array();
    foreach ($variables['options']['mapping'] as $type => $field_names) {
      if (!is_array($field_names)) {
        $field_names = array(
          $field_names,
        );
      }
      foreach ($field_names as $field_name) {
        if ($value = $variables['view']->style_plugin
          ->get_field($delta, $field_name)) {
          $fields[$type . '-' . $field_name] = $type . ':' . $value;
        }
      }
    }

    // If there are no fields in this row, skip to the next one.
    if (empty($fields)) {
      continue;
    }

    // Build a container for the row.
    $variables['element'][$delta] = array(
      '#type' => 'container',
      '#attributes' => array(
        'class' => array(
          'views-row-mapping-test',
        ),
      ),
    );

    // Add each field to the row.
    foreach ($fields as $key => $render) {
      $variables['element'][$delta][$key] = array(
        '#children' => $render,
        '#type' => 'container',
        '#attributes' => array(
          'class' => array(
            $key,
          ),
        ),
      );
    }
  }
}