BootstrapTabShortcode.php in Bootstrap 3 shortcodes 8
Adds shortcodes for all Bootstrap elements.
Namespace
Drupal\bs_shortcodes\Plugin\ShortcodeFile
src/Plugin/Shortcode/BootstrapTabShortcode.phpView source
<?php
/**
* @file
* Adds shortcodes for all Bootstrap elements.
*/
namespace Drupal\bs_shortcodes\Plugin\Shortcode;
use Drupal\Component\Utility\Html;
use Drupal\Core\Language\Language;
use Drupal\shortcode\Plugin\ShortcodeBase;
/**
* @Shortcode(
* id = "bs_tab",
* token = "tab",
* title = @Translation("Tab"),
* description = @Translation("Bootstrap 3 shortcode"),
* weight = 50
* )
*
* @author Filip Stefansson
* @since 1.0
*/
class BootstrapTabShortcode extends ShortcodeBase {
public function process(array $attributes, $content, $langcode = Language::LANGCODE_NOT_SPECIFIED) {
$attributes = $this
->getAttributes(array(
'title' => '',
'active' => '',
'fade' => '',
'xclass' => '',
'data' => '',
), $attributes);
$replace = array(
' ',
'.',
);
$class = 'tab-pane';
$class .= $attributes['fade'] != '' ? ' fade' : '';
$class .= $attributes['active'] != '' ? ' active' : '';
$class .= $attributes['active'] != '' && $attributes['fade'] != '' ? ' in' : '';
if (!isset($GLOBALS['tabs_count'])) {
$GLOBALS['tabs_count'] = 0;
}
$id = Html::cleanCssIdentifier('custom-tab-' . $GLOBALS['tabs_count'] . '-' . Html::escape($attributes['title']));
$data_props = _bs_shortcodes_parse_data_attributes($attributes['data']);
// We need to pass the title attribute to the tabs shortcode here ~Jur
return sprintf('<div id="%s" title="%s" class="%s"%s>%s</div>', Html::escape($id), Html::escape($attributes['title']), Html::escape($class), $data_props ? ' ' . $data_props : '', $content);
}
/**
* {@inheritdoc}
*/
public function tips($long = FALSE) {
$output = array();
$output[] = '<p><strong>[tab title="</strong>any text<strong>"</strong> active="true, <u>false</u>" fade="true, <u>false</u>" xclass="any text" data="any text"<strong>]</strong> ... <strong>[/tab]</strong>';
if ($long) {
$output[] = t('More info about this shortcode <a href=":url" target="_blank">here</a>', array(
':url' => 'https://github.com/MWDelaney/bootstrap-3-shortcodes#tab-parameters',
)) . '.</p>';
}
else {
$output[] = t('More info <a href=":url" target="_blank">here</a>', array(
':url' => 'https://github.com/MWDelaney/bootstrap-3-shortcodes#tab-parameters',
)) . '.</p>';
}
return implode(' ', $output);
}
}
Classes
Name![]() |
Description |
---|---|
BootstrapTabShortcode | @Shortcode( id = "bs_tab", token = "tab", title = @Translation("Tab"), description = @Translation("Bootstrap 3 shortcode"), weight = 50 ) |