Helper module for Views tests.
<?php
/**
* @file
* Helper module for Views tests.
*/
use Drupal\views\ViewExecutable;
/**
* Implements hook_permission().
*/
function views_test_data_permission() {
return array(
'views_test_data test permission' => array(
'title' => t('Test permission'),
'description' => t('views_test_data test permission'),
),
);
}
/**
* Access callback for the generic handler test.
*
* @return bool
* Returns views_test_data.tests->handler_access_callback config. so the user
* has access to the handler.
*
* @see Drupal\views\Tests\Handler\HandlerTest
*/
function views_test_data_handler_test_access_callback() {
return config('views_test_data.tests')
->get('handler_access_callback');
}
/**
* Access callback with an argument for the generic handler test.
*
* @param bool $argument
* A parameter to test that an argument got passed.
*
* @return bool
* Returns views_test_data.tests->handler_access_callback_argument, so the
* use has access to the handler.
*
* @see Drupal\views\Tests\Handler\HandlerTest
*/
function views_test_data_handler_test_access_callback_argument($argument = FALSE) {
// Check the argument to be sure that access arguments are passed into the
// callback.
if ($argument) {
return config('views_test_data.tests')
->get('handler_access_callback_argument');
}
else {
return FALSE;
}
}
/**
* Implements hook_preprocess_HOOK() for views-view-table.tpl.php.
*/
function views_test_data_preprocess_views_view_table(&$variables) {
if ($variables['view']->storage
->id() == 'test_view_render') {
$views_render_test = Drupal::state()
->get('views_render.test');
$views_render_test++;
Drupal::state()
->set('views_render.test', $views_render_test);
}
}
/**
* Implements hook_preprocess_HOOK() for theme_views_view_mapping_test().
*/
function template_preprocess_views_view_mapping_test(&$variables) {
$variables['element'] = array();
foreach ($variables['rows'] as $delta => $row) {
$fields = array();
foreach ($variables['options']['mapping'] as $type => $field_names) {
if (!is_array($field_names)) {
$field_names = array(
$field_names,
);
}
foreach ($field_names as $field_name) {
if ($value = $variables['view']->style_plugin
->getField($delta, $field_name)) {
$fields[$type . '-' . $field_name] = $type . ':' . $value;
}
}
}
// If there are no fields in this row, skip to the next one.
if (empty($fields)) {
continue;
}
// Build a container for the row.
$variables['element'][$delta] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'views-row-mapping-test',
),
),
);
// Add each field to the row.
foreach ($fields as $key => $render) {
$variables['element'][$delta][$key] = array(
'#children' => $render,
'#type' => 'container',
'#attributes' => array(
'class' => array(
$key,
),
),
);
}
}
}
/**
* Returns HTML for the Mapping Test style.
*/
function theme_views_view_mapping_test($variables) {
return drupal_render($variables['element']);
}
Name | Description |
---|---|
template_preprocess_views_view_mapping_test | Implements hook_preprocess_HOOK() for theme_views_view_mapping_test(). |
theme_views_view_mapping_test | Returns HTML for the Mapping Test style. |
views_test_data_handler_test_access_callback | Access callback for the generic handler test. |
views_test_data_handler_test_access_callback_argument | Access callback with an argument for the generic handler test. |
views_test_data_permission | Implements hook_permission(). |
views_test_data_preprocess_views_view_table | Implements hook_preprocess_HOOK() for views-view-table.tpl.php. |