BootstrapAccordion.php in Bootstrap Quick Tabs 8
File
src/Plugin/TabRenderer/BootstrapAccordion.php
View source
<?php
namespace Drupal\bootstrap_quicktabs\Plugin\TabRenderer;
use Drupal\quicktabs\TabRendererBase;
use Drupal\quicktabs\Entity\QuickTabsInstance;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class BootstrapAccordion extends TabRendererBase {
use StringTranslationTrait;
public function render(QuickTabsInstance $instance) {
$qt_id = $instance
->id();
$type = \Drupal::service('plugin.manager.tab_type');
$build = [];
$build['#theme_wrappers'] = [
'container' => [
'#attributes' => [
'class' => [
'panel-group',
],
'id' => 'panel-group-' . $qt_id,
],
],
];
$panels = [];
foreach ($instance
->getConfigurationData() as $index => $tab) {
$qsid = 'quickset-' . $qt_id;
$object = $type
->createInstance($tab['type']);
$render = $object
->render($tab);
$panel_id = $qsid . '-' . $index;
if ($instance
->getHideEmptyTabs() && empty($render)) {
continue;
}
$active_tab = $instance
->getDefaultTab() == 9999 ? 0 : $instance
->getDefaultTab();
$panel_class = '';
if ($active_tab == $index) {
$panel_class = 'in';
}
if (!empty($tab['content'][$tab['type']]['options']['display_title']) && !empty($tab['content'][$tab['type']]['options']['block_title'])) {
$build['pages'][$index]['#title'] = $tab['content'][$tab['type']]['options']['block_title'];
}
$panel = [
'id' => $panel_id,
'classes' => $panel_class,
'title' => new TranslatableMarkup($tab['title']),
'content' => render($render),
];
$panels["{$panel_id}"] = $panel;
}
$build['#theme'] = 'bootstrap_accordion';
$build['#panels'] = $panels;
$build['#id'] = $qt_id;
return $build;
}
}