You are here

class AccordionTabs in Quick Tabs 8.3

Provides an 'AccordionTabs' tab renderer.

Plugin annotation


@TabRenderer(
  id = "accordion_tabs",
  name = @Translation("accordion"),
)

Hierarchy

Expanded class hierarchy of AccordionTabs

File

quicktabs_accordion/src/Plugin/TabRenderer/AccordionTabs.php, line 18

Namespace

Drupal\quicktabs_accordion\Plugin\TabRenderer
View 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

Namesort descending Modifiers Type Description Overrides
AccordionTabs::optionsForm public function Return form elements used on the edit/add from. Overrides TabRendererBase::optionsForm
AccordionTabs::render public function Return a render array for the whole Quick Tabs instance. Overrides TabRendererBase::render
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 92
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TabRendererBase::getName public function Gets the name of the plugin.