You are here

public function BootstrapTabShortcode::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/BootstrapTabShortcode.php, line 27
Adds shortcodes for all Bootstrap elements.

Class

BootstrapTabShortcode
@Shortcode( id = "bs_tab", token = "tab", title = @Translation("Tab"), description = @Translation("Bootstrap 3 shortcode"), weight = 50 )

Namespace

Drupal\bs_shortcodes\Plugin\Shortcode

Code

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);
}