You are here

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

Class

BootstrapColumnShortcode
@Shortcode( id = "bs_column", token = "column", title = @Translation("Column"), 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(
    'xs' => '',
    'sm' => '',
    'md' => '',
    'lg' => '',
    'offset_xs' => '',
    'offset_sm' => '',
    'offset_md' => '',
    'offset_lg' => '',
    'pull_xs' => '',
    'pull_sm' => '',
    'pull_md' => '',
    'pull_lg' => '',
    'push_xs' => '',
    'push_sm' => '',
    'push_md' => '',
    'push_lg' => '',
    'xclass' => '',
    'data' => '',
  ), $attributes);
  $class = '';
  $class .= $attributes['lg'] ? ' col-lg-' . $attributes['lg'] : '';
  $class .= $attributes['md'] ? ' col-md-' . $attributes['md'] : '';
  $class .= $attributes['sm'] ? ' col-sm-' . $attributes['sm'] : '';
  $class .= $attributes['xs'] ? ' col-xs-' . $attributes['xs'] : '';
  $class .= is_numeric($attributes['offset_lg']) ? ' col-lg-offset-' . $attributes['offset_lg'] : '';
  $class .= is_numeric($attributes['offset_md']) ? ' col-md-offset-' . $attributes['offset_md'] : '';
  $class .= is_numeric($attributes['offset_sm']) ? ' col-sm-offset-' . $attributes['offset_sm'] : '';
  $class .= is_numeric($attributes['offset_xs']) ? ' col-xs-offset-' . $attributes['offset_xs'] : '';
  $class .= is_numeric($attributes['pull_lg']) ? ' col-lg-pull-' . $attributes['pull_lg'] : '';
  $class .= is_numeric($attributes['pull_md']) ? ' col-md-pull-' . $attributes['pull_md'] : '';
  $class .= is_numeric($attributes['pull_sm']) ? ' col-sm-pull-' . $attributes['pull_sm'] : '';
  $class .= is_numeric($attributes['pull_xs']) ? ' col-xs-pull-' . $attributes['pull_xs'] : '';
  $class .= is_numeric($attributes['push_lg']) ? ' col-lg-push-' . $attributes['push_lg'] : '';
  $class .= is_numeric($attributes['push_md']) ? ' col-md-push-' . $attributes['push_md'] : '';
  $class .= is_numeric($attributes['push_sm']) ? ' col-sm-push-' . $attributes['push_sm'] : '';
  $class .= is_numeric($attributes['push_xs']) ? ' col-xs-push-' . $attributes['push_xs'] : '';
  $class .= $attributes['xclass'] ? ' ' . $attributes['xclass'] : '';
  $data_props = _bs_shortcodes_parse_data_attributes($attributes['data']);
  return sprintf('<div class="%s"%s>%s</div>', Html::escape($class), $data_props ? ' ' . $data_props : '', $content);
}