function template_preprocess_views_view_simple_timeline in A Simple Timeline 8
Prepares variables for Simple Timeline template.
Default template: views-view-simple-timeline.html.twig.
Parameters
array $variables: An associative array containing:
- view: A View object.
File
- ./
simple_timeline.module, line 49 - Contains simple_timeline.module.
Code
function template_preprocess_views_view_simple_timeline(&$variables) {
$view = $variables['view'];
$rows = $variables['rows'];
$style = $view->style_plugin;
$options = $style->options;
// Add our specific class.
$variables['list']['attributes'] = new Attribute([
'class' => 'timeline-list',
]);
// Fetch classes from options.
if ($options['class']) {
$class = explode(' ', $options['class']);
$class = array_map('\\Drupal\\Component\\Utility\\Html::cleanCssIdentifier', $class);
$variables['list']['attributes']
->addClass($class);
}
if ($options['position_items']) {
$variables['list']['attributes']
->addClass($options['position_items']);
}
if ($options['position_marker']) {
$variables['list']['attributes']
->addClass($options['position_marker']);
}
// Fetch wrapper classes from handler options.
if ($options['wrapper_class']) {
$wrapper_class = explode(' ', $options['wrapper_class']);
$variables['attributes']['class'] = array_map('\\Drupal\\Component\\Utility\\Html::cleanCssIdentifier', $wrapper_class);
}
$count = 0;
$variables['default_row_class'] = !empty($options['default_row_class']);
foreach ($rows as $id => $row) {
$count++;
$variables['rows'][$id] = [];
$variables['rows'][$id]['content'] = $row;
$variables['rows'][$id]['attributes'] = new Attribute([
'class' => 'timeline-item clearfix',
]);
// Add odd/even class.
$odd = $count % 2 ? 'odd' : 'even';
$variables['rows'][$id]['attributes']
->addClass($odd);
if ($row_class = $view->style_plugin
->getRowClass($id)) {
$variables['rows'][$id]['attributes']
->addClass($row_class);
}
}
}