You are here

blocktabs.module in Block Tabs 8

Provides block tabs.

File

blocktabs.module
View source
<?php

/**
 * @file
 * Provides block tabs.
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function blocktabs_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'entity.blocktabs.collection':
      return '<p>' . t('Block tabs commonly provide a block which contains several tabs.') . '</p>';
  }
}

/**
 * Implements hook_theme().
 */
function blocktabs_theme() {
  return [
    'blocktabs' => [
      'render element' => 'elements',
    ],
    'blocktabs__accordion' => [
      'render element' => 'elements',
      'base hook' => 'blocktabs',
    ],
  ];
}

/**
 * Implements hook_theme_suggestions_HOOK().
 */
function blocktabs_theme_suggestions_blocktabs(array $variables) {
  $suggestions = [];
  $blocktabs = $variables['elements']['#blocktabs'];
  $style = $blocktabs
    ->getStyle();

  // drupal_set_message('$style:' .$style);
  if (!empty($style)) {
    $suggestions[] = 'blocktabs__' . $style;
  }
  $tabs_id = $blocktabs
    ->id();
  if (!empty($tabs_id)) {
    $suggestions[] = 'blocktabs__' . $tabs_id;
  }
  return $suggestions;
}

/**
 * Prepares variables for blocktabs templates.
 */
function template_preprocess_blocktabs(&$variables) {
  $blocktabs = $variables['elements']['#blocktabs'];
  $tabs_id = 'blocktabs-' . $blocktabs
    ->id();
  $variables['tabs_id'] = $tabs_id;
  $classes_array = [];
  $classes_array[] = 'blocktabs';
  $event = $blocktabs
    ->getEvent();
  if (!empty($event)) {
    $classes_array[] = $event;
  }
  $style = $blocktabs
    ->getStyle();
  if (!empty($style)) {
    $classes_array[] = $style;
  }
  $variables['attributes']['class'] = $classes_array;
  $variables['tabs'] = [];
  $tabs = $blocktabs
    ->getTabs();
  foreach ($tabs as $tab) {
    $tab_id = $tabs_id . '-' . $tab
      ->getWeight();
    $tab_obj = new stdClass();
    $tab_obj->title = $tab
      ->getTitle();
    $tab_obj->id = $tab_id;
    $tab_obj->content = $tab
      ->getContent();
    if (!empty($tab_obj->content)) {
      $variables['tabs'][$tab_id] = $tab_obj;
    }
  }
}

Functions

Namesort descending Description
blocktabs_help Implements hook_help().
blocktabs_theme Implements hook_theme().
blocktabs_theme_suggestions_blocktabs Implements hook_theme_suggestions_HOOK().
template_preprocess_blocktabs Prepares variables for blocktabs templates.