5 * Helper module for Views tests.
8 use Drupal\Core\Form\FormStateInterface;
11 * Access callback for the generic handler test.
14 * Returns views_test_data.tests->handler_access_callback config. so the user
15 * has access to the handler.
17 * @see \Drupal\views\Tests\Handler\HandlerTest
19 function views_test_data_handler_test_access_callback() {
20 return \Drupal::config('views_test_data.tests')->get('handler_access_callback');
24 * Access callback with an argument for the generic handler test.
26 * @param bool $argument
27 * A parameter to test that an argument got passed.
30 * Returns views_test_data.tests->handler_access_callback_argument, so the
31 * use has access to the handler.
33 * @see \Drupal\views\Tests\Handler\HandlerTest
35 function views_test_data_handler_test_access_callback_argument($argument = FALSE) {
36 // Check the argument to be sure that access arguments are passed into the
39 return \Drupal::config('views_test_data.tests')->get('handler_access_callback_argument');
47 * Implements hook_preprocess_HOOK() for views table templates.
49 function views_test_data_preprocess_views_view_table(&$variables) {
50 if ($variables['view']->storage->id() == 'test_view_render') {
51 $views_render_test = \Drupal::state()->get('views_render.test');
53 \Drupal::state()->set('views_render.test', $views_render_test);
58 * Prepares variables for the mapping row style test templates.
60 * Default template: views-view-mapping-test.html.twig.
62 * @param array $variables
63 * An associative array containing:
64 * - rows: A list of view rows.
65 * - options: Various view options, including the row style mapping.
66 * - view: The view object.
68 function template_preprocess_views_view_mapping_test(&$variables) {
69 $variables['element'] = [];
71 foreach ($variables['rows'] as $delta => $row) {
73 foreach ($variables['options']['mapping'] as $type => $field_names) {
74 if (!is_array($field_names)) {
75 $field_names = [$field_names];
77 foreach ($field_names as $field_name) {
78 if ($value = $variables['view']->style_plugin->getField($delta, $field_name)) {
79 $fields[$type . '-' . $field_name] = $type . ':' . $value;
84 // If there are no fields in this row, skip to the next one.
89 // Build a container for the row.
90 $variables['element'][$delta] = [
91 '#type' => 'container',
94 'views-row-mapping-test',
99 // Add each field to the row.
100 foreach ($fields as $key => $render) {
101 $variables['element'][$delta][$key] = [
102 '#children' => $render,
103 '#type' => 'container',
115 * Test pre_render function.
117 * @param array $element
121 * The changed render array.
123 function views_test_data_test_pre_render_function($element) {
124 $element['#markup'] = 'views_test_data_test_pre_render_function executed';
129 * Implements hook_form_BASE_FORM_ID_alter().
131 function views_test_data_form_views_form_test_form_multiple_default_alter(&$form, FormStateInterface $form_state, $form_id) {
132 drupal_set_message(t('Test base form ID with Views forms and arguments.'));