views_test_data.module 3.12 KB
Newer Older
merlinofchaos's avatar
merlinofchaos committed
1 2 3 4 5 6 7
<?php

/**
 * @file
 * Helper module for Views tests.
 */

8 9
use Drupal\views\View;

merlinofchaos's avatar
merlinofchaos committed
10 11 12
/**
 * Implements hook_permission().
 */
13
function views_test_data_permission() {
merlinofchaos's avatar
merlinofchaos committed
14 15 16 17 18 19 20 21 22 23 24
  return array(
    'views_test test permission' => array(
      'title' => t('Test permission'),
      'description' => t('views_test test permission'),
    ),
  );
}

/**
 * Implements hook_views_api().
 */
25
function views_test_data_views_api() {
merlinofchaos's avatar
merlinofchaos committed
26 27
  return array(
    'api' => 3.0,
28
    'template path' => drupal_get_path('module', 'views_test_data') . '/templates',
merlinofchaos's avatar
merlinofchaos committed
29 30 31 32 33 34
  );
}

/**
 * Implements hook_views_data().
 */
35 36
function views_test_data_views_data() {
  return variable_get('views_test_views_data', array());
merlinofchaos's avatar
merlinofchaos committed
37 38
}

39
function views_test_data_test_static_access_callback($access) {
merlinofchaos's avatar
merlinofchaos committed
40 41 42
  return $access;
}

43
function views_test_data_test_dynamic_access_callback($access, $argument1, $argument2) {
merlinofchaos's avatar
merlinofchaos committed
44 45
  return $access && $argument1 == variable_get('test_dynamic_access_argument1', NULL) && $argument2 == variable_get('test_dynamic_access_argument2', NULL);
}
46 47 48 49

/**
 * Implements hook_views_pre_render().
 */
50
function views_test_data_views_pre_render(&$view) {
51 52 53 54 55 56
  if ($view->name == 'test_cache_header_storage') {
    drupal_add_js(drupal_get_path('module', 'views_test') . '/views_cache.test.js');
    drupal_add_css(drupal_get_path('module', 'views_test') . '/views_cache.test.css');
    $view->pre_render_called = TRUE;
  }
}
57 58 59 60

/**
 * Implements hook_views_post_build().
 */
61
function views_test_data_views_post_build(View &$view) {
62 63 64 65 66 67 68 69 70
  if ($view->name == 'test_page_display') {
    if ($view->current_display == 'page_1') {
      $view->build_info['denied'] = TRUE;
    }
    elseif ($view->current_display == 'page_2') {
      $view->build_info['fail'] = TRUE;
    }
  }
}
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126

/**
 * Implements hook_preprocess_HOOK() for theme_views_view_mapping_test().
 */
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,
          ),
        ),
      );
    }
  }
}

/**
 * Returns HTML for the Mapping Test style.
 */
function theme_views_view_mapping_test($variables) {
  return drupal_render($variables['element']);
}