views_vertical_tabs.module in Views vertical tabs style plugin 8
Same filename and directory in other branches
Views vertical_tabs style plugin code.
File
views_vertical_tabs.moduleView source
<?php
/**
* @file
* Views vertical_tabs style plugin code.
*/
use Drupal\Component\Utility\Html;
use Drupal\Core\Render\Element\VerticalTabs;
use Drupal\Core\Render\Element\RenderElement;
use Drupal\Core\Form\FormState;
/**
* Implements hook_preprocess_HOOK() for theme_views_view_vertical_tabs().
*/
function template_preprocess_views_view_vertical_tabs(&$variables) {
/** @var \Drupal\views\ViewExecutable $view */
$view = $variables['view'];
$rows = $variables['rows'];
$style = $view->style_plugin;
$options = $style->options;
$group = $view->storage
->id() . '-' . $view->current_display;
$element['views_vertical_tabs'] = array(
'#type' => 'vertical_tabs',
'#title' => t('Views Vertical Tabs'),
'#attached' => array(
'library' => array(
'views_vertical_tabs/drupal.views-vertical-tabs',
),
),
'#parents' => array(
'views_vertical_tabs',
),
'#default_tab' => '',
);
$form = array();
$form_state = new FormState();
$element['views_vertical_tabs'] += VerticalTabs::processVerticalTabs($element['views_vertical_tabs'], $form_state, $form);
RenderElement::processGroup($element['views_vertical_tabs']['group'], $form_state, $form);
$default_row_class = isset($options['default_row_class']) ? $options['default_row_class'] : FALSE;
$row_class_special = isset($options['row_class_special']) ? $options['row_class_special'] : FALSE;
// Set up striping values.
$count = 0;
$max = count($rows);
$summaries = array();
foreach ($rows as $id => $row) {
$html_id = Html::getUniqueId($group . '-row-' . ($id + 1));
$classes = array();
$count++;
if ($default_row_class) {
$classes[] = 'views-row';
$classes[] = 'views-row-' . $count;
}
if ($row_class_special) {
$classes[] = 'views-row-' . ($count % 2 ? 'odd' : 'even');
if ($count == 1) {
$classes[] = 'views-row-first';
}
if ($count == $max) {
$classes[] = 'views-row-last';
}
}
if ($row_class = $view->style_plugin
->getRowClass($id)) {
$classes[] = $row_class;
}
$field = $options['title'];
$title = '';
if (isset($view->field[$field])) {
$title = $style
->getField($id, $field);
if ($view->field[$field]->options['label']) {
$title = $view->field[$field]->options['label'] . ': ' . $title;
}
$title = strip_tags(htmlspecialchars_decode($title));
}
$field = $options['description'];
$description = '';
if (isset($view->field[$field])) {
$description = $style
->getField($id, $field);
if ($view->field[$field]->options['label']) {
$description = $view->field[$field]->options['label'] . ': ' . $description;
}
$description = strip_tags(htmlspecialchars_decode($description));
}
$field = $options['summary'];
$summary = '';
if (isset($view->field[$field])) {
$summary = $style
->getField($id, $field);
if ($view->field[$field]->options['label']) {
$summary = $view->field[$field]->options['label'] . ': ' . $summary;
}
$summary = strip_tags(htmlspecialchars_decode($summary));
}
if (!empty($summary)) {
$summaries[$html_id] = $summary;
}
$element['row-' . $id] = array(
'#title' => $title,
'#type' => 'details',
'#group' => 'views_vertical_tabs',
'#collapsed' => TRUE,
'#children' => $row,
'#description' => $description,
'#attributes' => array(
'class' => $classes,
'id' => $html_id,
),
'#parents' => array(
'row-' . $id,
),
);
RenderElement::processGroup($element['row-' . $id], $form_state, $form);
}
$element['views_vertical_tabs']['#attached']['drupalSettings'] = array(
'views_vertical_tabs' => array(
$group => $summaries,
),
);
$variables['vertical_tabs'] = $element;
}
Functions
Name | Description |
---|---|
template_preprocess_views_view_vertical_tabs | Implements hook_preprocess_HOOK() for theme_views_view_vertical_tabs(). |