Same name in other branches
- 8.x-3.x src/Plugin/views/style/Quicktabs.php \Drupal\quicktabs\Plugin\views\style\Quicktabs::renderGroupingSets()
File
-
src/
Plugin/ views/ style/ Quicktabs.php, line 125
Class
- Quicktabs
- Style plugin to render views rows as tabs.
Namespace
Drupal\quicktabs\Plugin\views\styleCode
public function renderGroupingSets($sets, $level = 0) {
$output = [];
$theme_functions = $this->view
->buildThemeFunctions($this->groupingTheme);
$tab_titles = [];
$link_classes = [
'loaded',
];
$quicktab_id = str_replace('_', '-', $this->view
->id());
$set_count = 0;
foreach ($sets as $index => $set) {
$wrapper_attributes = [];
if ($set_count === 0) {
$wrapper_attributes['class'] = [
'active',
];
}
$tab_titles[] = [
'0' => Link::fromTextAndUrl(new TranslatableMarkup(Xss::filter($index, [
'img',
'em',
'strong',
'h2',
'h3',
'h4',
'h5',
'h6',
'small',
'span',
'i',
'br',
])), Url::fromRoute('<current>', [], [
'attributes' => [
'class' => $link_classes,
],
]))->toRenderable(),
'#wrapper_attributes' => $wrapper_attributes,
];
$level = isset($set['level']) ? $set['level'] : 0;
$row = reset($set['rows']);
// Render as a grouping set.
if (is_array($row) && isset($row['group'])) {
$single_output = [
'#theme' => $theme_functions,
'#view' => $this->view,
'#grouping' => $this->options['grouping'][$level],
'#rows' => $set['rows'],
];
}
else {
if ($this->usesRowPlugin()) {
foreach ($set['rows'] as $index => $row) {
$this->view->row_index = $index;
$set['rows'][$index] = $this->view->rowPlugin
->render($row);
}
}
$single_output = $this->renderRowGroup($set['rows']);
}
$single_output['#grouping_level'] = $level;
$single_output['#title'] = $set['group'];
// Create a mapping of which rows belong in which set
// This can then be used in the theme function to wrap each tab page.
if (!empty($this->options['grouping'])) {
$set_mapping = [];
foreach ($sets as $set_index => $set) {
foreach ($set['rows'] as $row_index => $row) {
$set_mapping[$set_index][] = $row_index;
}
}
}
$output[] = $single_output;
$set_count++;
}
$this->setSetMapping($set_mapping);
unset($this->view->row_index);
// Create the tabs for rendering.
$tabs = [
'#theme' => 'item_list',
'#items' => $tab_titles,
'#attributes' => [
'class' => [
'quicktabs-tabs',
],
],
];
$this->setTabs($tabs);
// Add quicktabs wrapper to all the output.
$output['#theme_wrappers'] = [
'container' => [
'#attributes' => [
'class' => [
'quicktabs-wrapper',
],
'id' => 'quicktabs-' . $quicktab_id,
],
],
];
return $output;
}