views_test_data.views_execution.inc 3.49 KB
Newer Older
1 2 3 4 5 6 7
<?php

/**
 * @file
 * Provides views data and hooks for views_test_data module.
 */

8
use Drupal\field\FieldStorageConfigInterface;
9
use Drupal\views\Plugin\views\cache\CachePluginBase;
10 11 12 13 14 15
use Drupal\views\ViewExecutable;

/**
 * Implements hook_views_query_substitutions().
 */
function views_test_data_views_query_substitutions(ViewExecutable $view) {
16
  \Drupal::state()->set('views_hook_test_views_query_substitutions', TRUE);
17 18 19 20 21 22
}

/**
 * Implements hook_views_form_substitutions().
 */
function views_test_data_views_form_substitutions(ViewExecutable $view) {
23
  \Drupal::state()->set('views_hook_test_views_form_substitutions', TRUE);
24 25 26 27 28
}

/**
 * Implements hook_field_views_data().
 */
29
function views_test_data_field_views_data(FieldStorageConfigInterface $field_storage) {
30
  \Drupal::state()->set('views_hook_test_field_views_data', TRUE);
31 32 33 34 35
}

/**
 * Implements hook_field_views_data_alter().
 */
36
function views_test_data_field_views_data_alter(&$data, FieldStorageConfigInterface $field_storage, $module) {
37
  \Drupal::state()->set('views_hook_test_field_views_data_alter', TRUE);
38 39 40 41 42 43 44 45 46
}

/**
 * Implements hook_views_pre_render().
 *
 * @see \Drupal\views\Tests\Plugin\CacheTest
 * @see \Drupal\views\Tests\Plugin\RenderTest
 */
function views_test_data_views_pre_render(ViewExecutable $view) {
47
  \Drupal::state()->set('views_hook_test_views_pre_render', TRUE);
48 49

  if (isset($view) && ($view->storage->id() == 'test_cache_header_storage')) {
50
    $view->element['#attached']['library'][] = 'views_test_data/test';
51
    $view->element['#attached']['drupalSettings']['foo'] = 'bar';
52
    $view->element['#attached']['placeholders']['non-existing-placeholder-just-for-testing-purposes']['#lazy_builder'] = ['views_test_data_placeholders', ['bar']];
53
    $view->element['#cache']['tags'][] = 'views_test_data:1';
54 55 56 57 58
    $view->build_info['pre_render_called'] = TRUE;
  }

}

59
/**
60
 * #lazy_builder callback; for testing purposes only.
61
 */
62
function views_test_data_placeholders() {
63
  // No-op.
64
  return [];
65 66
}

67 68 69
/**
 * Implements hook_views_post_render().
 */
70
function views_test_data_views_post_render(ViewExecutable $view, &$output, CachePluginBase $cache) {
71
  \Drupal::state()->set('views_hook_test_views_post_render', TRUE);
72 73 74 75 76 77
}

/**
 * Implements hook_views_pre_build().
 */
function views_test_data_views_pre_build(ViewExecutable $view) {
78
  \Drupal::state()->set('views_hook_test_views_pre_build', TRUE);
79 80 81 82 83 84
}

/**
 * Implements hook_views_post_build().
 */
function views_test_data_views_post_build(ViewExecutable $view) {
85
  \Drupal::state()->set('views_hook_test_views_post_build', TRUE);
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

  if (isset($view) && ($view->storage->id() == '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;
    }
  }
}

/**
 * Implements hook_views_pre_view().
 */
function views_test_data_views_pre_view(ViewExecutable $view) {
101
  \Drupal::state()->set('views_hook_test_views_pre_view', TRUE);
102 103 104 105 106 107
}

/**
 * Implements hook_views_pre_execute().
 */
function views_test_data_views_pre_execute(ViewExecutable $view) {
108
  \Drupal::state()->set('views_hook_test_views_pre_execute', TRUE);
109 110 111 112 113 114
}

/**
 * Implements hook_views_post_execute().
 */
function views_test_data_views_post_execute(ViewExecutable $view) {
115
  \Drupal::state()->set('views_hook_test_views_post_execute', TRUE);
116 117 118 119 120 121
}

/**
 * Implements hook_views_query_alter().
 */
function views_test_data_views_query_alter(ViewExecutable $view) {
122
  \Drupal::state()->set('views_hook_test_views_query_alter', TRUE);
123
}