views_test.module 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * @file
  4. * Helper module for Views tests.
  5. */
  6. /**
  7. * Implements hook_permission().
  8. */
  9. function views_test_permission() {
  10. return array(
  11. 'views_test test permission' => array(
  12. 'title' => t('Test permission'),
  13. 'description' => t('views_test test permission'),
  14. ),
  15. );
  16. }
  17. /**
  18. * Implements hook_views_api().
  19. */
  20. function views_test_views_api() {
  21. return array(
  22. 'api' => 3.0,
  23. 'template path' => drupal_get_path('module', 'views') . '/test_templates',
  24. );
  25. }
  26. /**
  27. * Implements hook_views_data().
  28. */
  29. function views_test_views_data() {
  30. // Count how often this hook is called.
  31. $count = variable_get('views_test_views_data_count', 0);
  32. $count++;
  33. variable_set('views_test_views_data_count', $count);
  34. return variable_get('views_test_views_data', array());
  35. }
  36. /**
  37. * Implements hook_views_plugins().
  38. */
  39. function views_test_views_plugins() {
  40. return variable_get('views_test_views_plugins', array());
  41. }
  42. function views_test_test_static_access_callback($access) {
  43. return $access;
  44. }
  45. function views_test_test_dynamic_access_callback($access, $argument1, $argument2) {
  46. return $access && $argument1 == variable_get('test_dynamic_access_argument1', NULL) && $argument2 == variable_get('test_dynamic_access_argument2', NULL);
  47. }
  48. /**
  49. * Implements hook_views_pre_render().
  50. */
  51. function views_test_views_pre_render(&$view) {
  52. if ($view->name == 'test_cache_header_storage') {
  53. drupal_add_js(drupal_get_path('module', 'views_test') . '/views_cache.test.js');
  54. drupal_add_css(drupal_get_path('module', 'views_test') . '/views_cache.test.css');
  55. $view->pre_render_called = TRUE;
  56. }
  57. }
  58. /**
  59. * Implements hook_preprocess_HOOK() for theme_views_view_mapping_test().
  60. */
  61. function template_preprocess_views_view_mapping_test(&$variables) {
  62. $variables['element'] = array();
  63. foreach ($variables['rows'] as $delta => $row) {
  64. $fields = array();
  65. foreach ($variables['options']['mapping'] as $type => $field_names) {
  66. if (!is_array($field_names)) {
  67. $field_names = array($field_names);
  68. }
  69. foreach ($field_names as $field_name) {
  70. if ($value = $variables['view']->style_plugin->get_field($delta, $field_name)) {
  71. $fields[$type . '-' . $field_name] = $type . ':' . $value;
  72. }
  73. }
  74. }
  75. // If there are no fields in this row, skip to the next one.
  76. if (empty($fields)) {
  77. continue;
  78. }
  79. // Build a container for the row.
  80. $variables['element'][$delta] = array(
  81. '#type' => 'container',
  82. '#attributes' => array(
  83. 'class' => array(
  84. 'views-row-mapping-test',
  85. ),
  86. ),
  87. );
  88. // Add each field to the row.
  89. foreach ($fields as $key => $render) {
  90. $variables['element'][$delta][$key] = array(
  91. '#children' => $render,
  92. '#type' => 'container',
  93. '#attributes' => array(
  94. 'class' => array(
  95. $key,
  96. ),
  97. ),
  98. );
  99. }
  100. }
  101. }
  102. /**
  103. * Returns HTML for the Mapping Test style.
  104. */
  105. function theme_views_view_mapping_test($variables) {
  106. return drupal_render($variables['element']);
  107. }