function template_preprocess_views_view_mapping_test in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/views/tests/modules/views_test_data/views_test_data.module \template_preprocess_views_view_mapping_test()
Prepares variables for the mapping row style test templates.
Default template: views-view-mapping-test.html.twig.
Parameters
array $variables: An associative array containing:
- rows: A list of view rows.
- options: Various view options, including the row style mapping.
- view: The view object.
File
- core/
modules/ views/ tests/ modules/ views_test_data/ views_test_data.module, line 66 - Helper module for Views tests.
Code
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,
),
),
);
}
}
}