You are here

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

Class

BootstrapProgressBarShortcode
Plugin annotation @Shortcode( id = "bs_progress_bar", token = "progress_bar", title = @Translation("Progress Bar"), 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(
    'type' => '',
    'percent' => '',
    'label' => '',
    'xclass' => '',
    'data' => '',
  ), $attributes);
  $class = 'progress-bar';
  $class .= $attributes['type'] ? ' progress-bar-' . $attributes['type'] : '';
  $class .= $attributes['xclass'] ? ' ' . $attributes['xclass'] : '';
  $data_props = _bs_shortcodes_parse_data_attributes($attributes['data']);
  return sprintf('<div class="%s" role="progressbar" %s%s>%s</div>', Html::escape($class), $attributes['percent'] ? ' aria-value="' . (int) $attributes['percent'] . '" aria-valuemin="0" aria-valuemax="100" style="width: ' . (int) $attributes['percent'] . '%;"' : '', $data_props ? ' ' . $data_props : '', $attributes['percent'] ? sprintf('<span%s>%s</span>', !$attributes['label'] ? ' class="sr-only"' : '', (int) $attributes['percent'] . '% Complete') : '');
}