You are here

public function BootstrapColumnShortcode::process in Shortcode 2.0.x

Same name and namespace in other branches
  1. 8 shortcode_example/src/Plugin/Shortcode/BootstrapColumnShortcode.php \Drupal\shortcode_example\Plugin\Shortcode\BootstrapColumnShortcode::process()

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

shortcode_example/src/Plugin/Shortcode/BootstrapColumnShortcode.php, line 22

Class

BootstrapColumnShortcode
Provides a shortcode for bootstrap columns.

Namespace

Drupal\shortcode_example\Plugin\Shortcode

Code

public function process(array $attributes, $text, $langcode = Language::LANGCODE_NOT_SPECIFIED) {
  $attributes = $this
    ->getAttributes([
    'class' => '',
    'xs' => '',
    'sm' => '',
    'md' => '',
    'lg' => '',
  ], $attributes);
  $class = $attributes['class'];
  foreach ([
    'xs',
    'sm',
    'md',
    'lg',
  ] as $size) {
    if ($attributes[$size]) {
      $class = $this
        ->addClass($class, 'col-' . $size . '-' . $attributes[$size]);
    }
  }
  return '<div class="' . $class . '">' . $text . '</div>';
}