UiTabs.php in Quick Tabs 8.3
File
quicktabs_jqueryui/src/Plugin/TabRenderer/UiTabs.php
View source
<?php
namespace Drupal\quicktabs_jqueryui\Plugin\TabRenderer;
use Drupal\quicktabs\TabRendererBase;
use Drupal\quicktabs\Entity\QuickTabsInstance;
use Drupal\Core\Template\Attribute;
use Drupal\Core\StringTranslation\TranslatableMarkup;
class UiTabs extends TabRendererBase {
public function render(QuickTabsInstance $instance) {
$qt_id = $instance
->id();
$type = \Drupal::service('plugin.manager.tab_type');
$build = [];
$build['pages'] = [];
$tab_pages = [];
$titles = [];
foreach ($instance
->getConfigurationData() as $index => $tab) {
$object = $type
->createInstance($tab['type']);
$render = $object
->render($tab);
if ($instance
->getHideEmptyTabs() && empty($render)) {
continue;
}
$tab_num = $index + 1;
$attributes = new Attribute([
'id' => 'qt-' . $qt_id . '-ui-tabs' . $tab_num,
]);
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'];
}
$build['pages'][$index]['#block'] = $render;
$build['pages'][$index]['#prefix'] = '<div ' . $attributes . '>';
$build['pages'][$index]['#suffix'] = '</div>';
$build['pages'][$index]['#theme'] = 'quicktabs_block_content';
$href = '#qt-' . $qt_id . '-ui-tabs' . $tab_num;
$titles[] = [
'#markup' => '<a href="' . $href . '">' . new TranslatableMarkup($tab['title']) . '</a>',
];
$tab_pages[] = $tab;
}
$build['#theme_wrappers'] = [
'container' => [
'#attributes' => [
'class' => [
'quicktabs-ui-wrapper',
],
'id' => 'quicktabs-' . $qt_id,
],
],
];
$tabs = [
'#theme' => 'item_list',
'#items' => $titles,
];
array_unshift($build, $tabs);
$default_tab = $instance
->getDefaultTab();
$build['#attached'] = [
'library' => [
'quicktabs_jqueryui/quicktabs.ui',
],
'drupalSettings' => [
'quicktabs' => [
'qt_' . $qt_id => [
'tabs' => $tab_pages,
'default_tab' => $default_tab,
],
],
],
];
return $build;
}
}
Classes
Name |
Description |
UiTabs |
Provides a 'ui tabs' tab renderer. |