class AccordionTabs in Quick Tabs 8.3
Provides an 'AccordionTabs' tab renderer.
Plugin annotation
@TabRenderer(
id = "accordion_tabs",
name = @Translation("accordion"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\quicktabs\TabRendererBase implements TabRendererInterface
- class \Drupal\quicktabs_accordion\Plugin\TabRenderer\AccordionTabs uses StringTranslationTrait
- class \Drupal\quicktabs\TabRendererBase implements TabRendererInterface
Expanded class hierarchy of AccordionTabs
File
- quicktabs_accordion/
src/ Plugin/ TabRenderer/ AccordionTabs.php, line 18
Namespace
Drupal\quicktabs_accordion\Plugin\TabRendererView source
class AccordionTabs extends TabRendererBase {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function optionsForm(QuickTabsInstance $instance) {
$options = $instance
->getOptions()['accordion_tabs'];
$form = [];
$form['jquery_ui'] = [
'#type' => 'fieldset',
'#title' => $this
->t('JQuery UI options'),
];
$form['jquery_ui']['collapsible'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Collapsible'),
'#default_value' => $options['jquery_ui']['collapsible'] != NULL && $instance
->getRenderer() == 'accordion_tabs' ? $options['jquery_ui']['collapsible'] : 0,
];
$form['jquery_ui']['heightStyle'] = [
'#type' => 'radios',
'#title' => $this
->t('JQuery UI HeightStyle'),
'#options' => [
'auto' => $this
->t('auto'),
'fill' => $this
->t('fill'),
'content' => $this
->t('content'),
],
'#default_value' => $options['jquery_ui']['heightStyle'] != NULL && $instance
->getRenderer() == 'accordion_tabs' ? $options['jquery_ui']['heightStyle'] : 'auto',
];
return $form;
}
/**
* {@inheritdoc}
*/
public function render(QuickTabsInstance $instance) {
$qt_id = $instance
->id();
$type = \Drupal::service('plugin.manager.tab_type');
// The render array used to build the block.
$build = [];
$build['pages'] = [];
// Add a wrapper.
$build['#theme_wrappers'] = [
'container' => [
'#attributes' => [
'class' => [
'quicktabs-accordion',
],
'id' => 'quicktabs-' . $qt_id,
],
],
];
$tab_pages = [];
foreach ($instance
->getConfigurationData() as $index => $tab) {
$qsid = 'quickset-' . $qt_id;
$object = $type
->createInstance($tab['type']);
$render = $object
->render($tab);
// If user wants to hide empty tabs and there is no content
// then skip to next tab.
if ($instance
->getHideEmptyTabs() && empty($render)) {
continue;
}
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'] = '<h3><a href= "#' . $qsid . '_' . $index . '">' . new TranslatableMarkup($tab['title']) . '</a></h3><div>';
$build['pages'][$index]['#suffix'] = '</div>';
$build['pages'][$index]['#theme'] = 'quicktabs_block_content';
// Array of tab pages to pass as settings ////////////.
$tab['tab_page'] = $index;
$tab_pages[] = $tab;
}
$options = $instance
->getOptions()['accordion_tabs'];
$active_tab = $instance
->getDefaultTab() == 9999 ? 0 : $instance
->getDefaultTab();
$active = $instance
->getDefaultTab() == 9999 ? FALSE : (int) $instance
->getDefaultTab();
$collapsible = $instance
->getDefaultTab() == 9999 ? TRUE : (int) $options['jquery_ui']['collapsible'];
$build['#attached'] = [
'library' => [
'quicktabs_accordion/quicktabs.accordion',
],
'drupalSettings' => [
'quicktabs' => [
'qt_' . $qt_id => [
'tabs' => $tab_pages,
'active_tab' => $active_tab,
'options' => [
'active' => $active,
'heightStyle' => $options['jquery_ui']['heightStyle'],
'collapsible' => $collapsible,
],
],
],
],
];
return $build;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AccordionTabs:: |
public | function |
Return form elements used on the edit/add from. Overrides TabRendererBase:: |
|
AccordionTabs:: |
public | function |
Return a render array for the whole Quick Tabs instance. Overrides TabRendererBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TabRendererBase:: |
public | function | Gets the name of the plugin. |