views_test.module 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. return variable_get('views_test_views_data', array());
  31. }
  32. /**
  33. * Implements hook_views_plugins().
  34. */
  35. function views_test_views_plugins() {
  36. return variable_get('views_test_views_plugins', array());
  37. }
  38. function views_test_test_static_access_callback($access) {
  39. return $access;
  40. }
  41. function views_test_test_dynamic_access_callback($access, $argument1, $argument2) {
  42. return $access && $argument1 == variable_get('test_dynamic_access_argument1', NULL) && $argument2 == variable_get('test_dynamic_access_argument2', NULL);
  43. }
  44. /**
  45. * Implements hook_views_pre_render().
  46. */
  47. function views_test_views_pre_render(&$view) {
  48. if ($view->name == 'test_cache_header_storage') {
  49. drupal_add_js(drupal_get_path('module', 'views_test') . '/views_cache.test.js');
  50. drupal_add_css(drupal_get_path('module', 'views_test') . '/views_cache.test.css');
  51. $view->pre_render_called = TRUE;
  52. }
  53. }
  54. /**
  55. * Implements hook_preprocess_HOOK() for theme_views_view_mapping_test().
  56. */
  57. function template_preprocess_views_view_mapping_test(&$variables) {
  58. $variables['element'] = array();
  59. foreach ($variables['rows'] as $delta => $row) {
  60. $fields = array();
  61. foreach ($variables['options']['mapping'] as $type => $field_names) {
  62. if (!is_array($field_names)) {
  63. $field_names = array($field_names);
  64. }
  65. foreach ($field_names as $field_name) {
  66. if ($value = $variables['view']->style_plugin->get_field($delta, $field_name)) {
  67. $fields[$type . '-' . $field_name] = $type . ':' . $value;
  68. }
  69. }
  70. }
  71. // If there are no fields in this row, skip to the next one.
  72. if (empty($fields)) {
  73. continue;
  74. }
  75. // Build a container for the row.
  76. $variables['element'][$delta] = array(
  77. '#type' => 'container',
  78. '#attributes' => array(
  79. 'class' => array(
  80. 'views-row-mapping-test',
  81. ),
  82. ),
  83. );
  84. // Add each field to the row.
  85. foreach ($fields as $key => $render) {
  86. $variables['element'][$delta][$key] = array(
  87. '#children' => $render,
  88. '#type' => 'container',
  89. '#attributes' => array(
  90. 'class' => array(
  91. $key,
  92. ),
  93. ),
  94. );
  95. }
  96. }
  97. }
  98. /**
  99. * Returns HTML for the Mapping Test style.
  100. */
  101. function theme_views_view_mapping_test($variables) {
  102. return drupal_render($variables['element']);
  103. }