Projet

Général

Profil

Paste
Télécharger (3,03 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / tests / views_test.module @ 6eb8d15f

1
<?php
2

    
3
/**
4
 * @file
5
 * Helper module for Views tests.
6
 */
7

    
8
/**
9
 * Implements hook_permission().
10
 */
11
function views_test_permission() {
12
  return array(
13
    'views_test test permission' => array(
14
      'title' => t('Test permission'),
15
      'description' => t('views_test test permission'),
16
    ),
17
  );
18
}
19

    
20
/**
21
 * Implements hook_views_api().
22
 */
23
function views_test_views_api() {
24
  return array(
25
    'api' => 3.0,
26
    'template path' => drupal_get_path('module', 'views_test') . '/templates',
27
  );
28
}
29

    
30
/**
31
 * Implements hook_views_data().
32
 */
33
function views_test_views_data() {
34
  // Count how often this hook is called.
35
  $count = variable_get('views_test_views_data_count', 0);
36
  $count++;
37
  variable_set('views_test_views_data_count', $count);
38
  return  variable_get('views_test_views_data', array());
39
}
40

    
41
/**
42
 * Implements hook_views_plugins().
43
 */
44
function views_test_views_plugins() {
45
  return variable_get('views_test_views_plugins', array());
46
}
47

    
48
function views_test_test_static_access_callback($access) {
49
  return $access;
50
}
51

    
52
function views_test_test_dynamic_access_callback($access, $argument1, $argument2) {
53
  return $access && $argument1 == variable_get('test_dynamic_access_argument1', NULL) && $argument2 == variable_get('test_dynamic_access_argument2', NULL);
54
}
55

    
56
/**
57
 * Implements hook_views_pre_render().
58
 */
59
function views_test_views_pre_render(&$view) {
60
  if ($view->name == 'test_cache_header_storage') {
61
    drupal_add_js(drupal_get_path('module', 'views_test') . '/views_cache.test.js');
62
    drupal_add_css(drupal_get_path('module', 'views_test') . '/views_cache.test.css');
63
    $view->pre_render_called = TRUE;
64
  }
65
}
66

    
67
/**
68
 * Implements hook_preprocess_HOOK() for theme_views_view_mapping_test().
69
 */
70
function template_preprocess_views_view_mapping_test(&$variables) {
71
  $variables['element'] = array();
72

    
73
  foreach ($variables['rows'] as $delta => $row) {
74
    $fields = array();
75
    foreach ($variables['options']['mapping'] as $type => $field_names) {
76
      if (!is_array($field_names)) {
77
        $field_names = array($field_names);
78
      }
79
      foreach ($field_names as $field_name) {
80
        if ($value = $variables['view']->style_plugin->get_field($delta, $field_name)) {
81
          $fields[$type . '-' . $field_name] = $type . ':' . $value;
82
        }
83
      }
84
    }
85

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

    
91
    // Build a container for the row.
92
    $variables['element'][$delta] = array(
93
      '#type' => 'container',
94
      '#attributes' => array(
95
        'class' => array(
96
          'views-row-mapping-test',
97
        ),
98
      ),
99
    );
100

    
101
    // Add each field to the row.
102
    foreach ($fields as $key => $render) {
103
      $variables['element'][$delta][$key] = array(
104
        '#children' => $render,
105
        '#type' => 'container',
106
        '#attributes' => array(
107
          'class' => array(
108
            $key,
109
          ),
110
        ),
111
      );
112
    }
113
  }
114
}
115

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