public function BootstrapCollapseShortcode::process in Bootstrap 3 shortcodes 8
Performs the shortcode processing.
Parameters
array $attributes: Array of attributes.
string $text: The text string to be processed.
string $langcode: The language code of the text to be filtered. Defaults to LANGCODE_NOT_SPECIFIED.
Return value
string The processed text.
Overrides ShortcodeInterface::process
File
- src/
Plugin/ Shortcode/ BootstrapCollapseShortcode.php, line 27 - Adds shortcodes for all Bootstrap elements.
Class
- BootstrapCollapseShortcode
- @Shortcode( id = "bs_collapse", token = "collapse", title = @Translation("Collapse"), description = @Translation("Bootstrap 3 shortcode"), weight = 50 )
Namespace
Drupal\bs_shortcodes\Plugin\ShortcodeCode
public function process(array $attributes, $content, $langcode = Language::LANGCODE_NOT_SPECIFIED) {
$attributes = $this
->getAttributes(array(
'title' => '',
'type' => '',
'active' => '',
'xclass' => '',
'data' => '',
), $attributes);
$panel_class = 'panel';
$panel_class .= $attributes['type'] ? ' panel-' . $attributes['type'] : ' panel-default';
$panel_class .= $attributes['xclass'] ? ' ' . $attributes['xclass'] : '';
$collapse_class = 'panel-collapse';
$collapse_class .= $attributes['active'] != '' ? ' in' : ' collapse';
if (!isset($GLOBALS['collapsibles_count'])) {
$GLOBALS['collapsibles_count'] = 0;
}
$parent = 'custom-collapse-' . $GLOBALS['collapsibles_count'];
$current_collapse = $parent . '-' . Html::escape($attributes['title']);
$data_props = _bs_shortcodes_parse_data_attributes($attributes['data']);
return sprintf('<div class="%1$s"%2$s>
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#%3$s" href="#%4$s">%5$s</a>
</h4>
</div>
<div id="%4$s" class="%6$s">
<div class="panel-body">%7$s</div>
</div>
</div>', Html::escape($panel_class), $data_props ? ' ' . $data_props : '', $parent, Html::getUniqueId($current_collapse), $attributes['title'], Html::escape($collapse_class), $content);
}