You are here

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

Class

BootstrapPanelShortcode
Plugin annotation @Shortcode( id = "bs_panel", token = "panel", title = @Translation("Panel"), 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' => '',
    'heading' => '',
    'type' => '',
    'footer' => '',
    'xclass' => '',
    'data' => '',
  ), $attributes);
  $class = 'panel';
  $class .= $attributes['type'] ? ' panel-' . $attributes['type'] : ' panel-default';
  $class .= $attributes['xclass'] ? ' ' . $attributes['xclass'] : '';
  if (!$attributes['heading'] && $attributes['title']) {
    $attributes['heading'] = $attributes['title'];
    $attributes['title'] = TRUE;
  }
  $data_props = _bs_shortcodes_parse_data_attributes($attributes['data']);
  $attributes['footer'] = $attributes['footer'] ? '<div class="panel-footer">' . $attributes['footer'] . '</div>' : '';
  if ($attributes['heading']) {
    $attributes['heading'] = sprintf('<div class="panel-heading">%s%s%s</div>', $attributes['title'] ? '<h3 class="panel-title">' : '', check_markup($attributes['heading']), $attributes['title'] ? '</h3>' : '');
  }
  else {
    $attributes['heading'] = '';
  }
  return sprintf('<div class="%s"%s>%s<div class="panel-body">%s</div>%s</div>', Html::escape($class), $data_props ? ' ' . $data_props : '', $attributes['heading'], $content, $attributes['footer'] ? ' ' . $attributes['footer'] : '');
}