class BootstrapTabsShortcode in Bootstrap 3 shortcodes 8
@Shortcode( id = "bs_tabs", token = "tabs", title = @Translation("Tabs"), description = @Translation("Bootstrap 3 shortcode"), weight = 50 )
@author Filip Stefansson @since 1.0 Modified by TwItCh twitch@designweapon.com Now acts a whole nav/tab/pill shortcode solution!
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\shortcode\Plugin\ShortcodeBase implements ShortcodeInterface
- class \Drupal\bs_shortcodes\Plugin\Shortcode\BootstrapTabsShortcode
- class \Drupal\shortcode\Plugin\ShortcodeBase implements ShortcodeInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of BootstrapTabsShortcode
File
- src/
Plugin/ Shortcode/ BootstrapTabsShortcode.php, line 27 - Adds shortcodes for all Bootstrap elements.
Namespace
Drupal\bs_shortcodes\Plugin\ShortcodeView source
class BootstrapTabsShortcode extends ShortcodeBase {
public function process(array $attributes, $content, $langcode = Language::LANGCODE_NOT_SPECIFIED) {
$attributes = $this
->getAttributes(array(
'type' => '',
'xclass' => '',
'data' => '',
), $attributes);
$ul_class = 'nav';
$ul_class .= $attributes['type'] ? ' nav-' . $attributes['type'] : ' nav-tabs';
$ul_class .= $attributes['xclass'] ? ' ' . $attributes['xclass'] : '';
$div_class = 'tab-content';
$id = Html::cleanCssIdentifier('custom-tabs-' . $GLOBALS['tabs_count']);
$data_props = _bs_shortcodes_parse_data_attributes($attributes['data']);
// $attrs_map = bs_attribute_map( $content );
// Because the Drupal API parses shortcodes from the inside out
// we need to do some libxml magic here
// ~Jur
$previous_value = libxml_use_internal_errors(TRUE);
$dom = new \DOMDocument();
$dom
->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'));
libxml_clear_errors();
libxml_use_internal_errors($previous_value);
$finder = new \DomXPath($dom);
$domNodes = $finder
->query("//div[contains(@class, tab-pane)]");
$attrs_map = array();
foreach ($domNodes as $domNode) {
if (strpos($domNode
->getAttribute('class'), 'active') === FALSE) {
$active = FALSE;
}
else {
$active = 'true';
}
$attrs_map[] = array(
'tab' => array(
'title' => $domNode
->getAttribute('title'),
'active' => $active,
),
);
}
// Extract the tab titles for use in the tab widget.
// Extract the tab titles for use in the tab widget.
if ($attrs_map) {
$tabs = array();
$GLOBALS['tabs_default_active'] = TRUE;
foreach ($attrs_map as $check) {
if (!empty($check["tab"]["active"])) {
$GLOBALS['tabs_default_active'] = FALSE;
}
}
$i = 0;
foreach ($attrs_map as $tab) {
$tabs[] = sprintf('<li%s><a href="#%s" data-toggle="tab">%s</a></li>', !empty($tab["tab"]["active"]) || $GLOBALS['tabs_default_active'] && $i == 0 ? ' class="active"' : '', Html::cleanCssIdentifier('custom-tab-' . $GLOBALS['tabs_count'] . '-' . Html::escape($tab["tab"]["title"])), $tab["tab"]["title"]);
$i++;
}
}
if (isset($GLOBALS['tabs_count'])) {
$GLOBALS['tabs_count']++;
}
else {
$GLOBALS['tabs_count'] = 0;
}
return sprintf('<ul class="%s" id="%s"%s>%s</ul><div class="%s">%s</div>', Html::escape($ul_class), Html::escape($id), $data_props ? ' ' . $data_props : '', $tabs ? implode($tabs) : '', Html::escape($div_class), $content);
}
/**
* {@inheritdoc}
*/
public function tips($long = FALSE) {
$output = array();
$output[] = '<p><strong>[tabs type="</strong><u>tabs</u>, pills<strong>"</strong> xclass="any text" data="any text"<strong>]</strong> ... <strong>[/tabs]</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#tabs',
)) . '.</p>';
}
else {
$output[] = t('More info <a href=":url" target="_blank">here</a>', array(
':url' => 'https://github.com/MWDelaney/bootstrap-3-shortcodes#tabs',
)) . '.</p>';
}
return implode(' ', $output);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BootstrapTabsShortcode:: |
public | function |
Performs the shortcode processing. Overrides ShortcodeInterface:: |
|
BootstrapTabsShortcode:: |
public | function |
Generates a filter's tip. Overrides ShortcodeBase:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
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. | |
ShortcodeBase:: |
protected | property |
The plugin ID of this filter. Overrides PluginBase:: |
|
ShortcodeBase:: |
public | property | The name of the provider that owns this filter. | |
ShortcodeBase:: |
public | property | An associative array containing the configured settings of this filter. | |
ShortcodeBase:: |
public | property | A Boolean indicating whether this filter is enabled. | |
ShortcodeBase:: |
public | function | Add a class into a classes string if not already inside. | |
ShortcodeBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
ShortcodeBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
ShortcodeBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
|
ShortcodeBase:: |
public | function | Combines user attributes with known attributes. | |
ShortcodeBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
ShortcodeBase:: |
public | function |
Returns the administrative description for this shortcode plugin. Overrides ShortcodeInterface:: |
|
ShortcodeBase:: |
public | function | Returns image properties for a given image media entity id. | |
ShortcodeBase:: |
public | function |
Returns the administrative label for this shortcode plugin. Overrides ShortcodeInterface:: |
|
ShortcodeBase:: |
public | function | Get a media entity field. | |
ShortcodeBase:: |
public | function | Get the file url for a media object. | |
ShortcodeBase:: |
public | function | Extracts the media id from a 'media/x' system path. | |
ShortcodeBase:: |
public | function | Returns a suitable title string given the user provided title and text. | |
ShortcodeBase:: |
public | function | ||
ShortcodeBase:: |
public | function | Returns a url to be used in a link element given path or url. | |
ShortcodeBase:: |
public | function | Wrapper for renderPlain. | |
ShortcodeBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
ShortcodeBase:: |
public | function |
Generates a shortcode's settings form. Overrides ShortcodeInterface:: |
|
ShortcodeBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
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. |