You are here

public function ShortcodeBase::addClass in Shortcode 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/ShortcodeBase.php \Drupal\shortcode\Plugin\ShortcodeBase::addClass()

Add a class into a classes string if not already inside.

Parameters

mixed|string|array $classes: The classes string or array.

string $new_class: The class to add.

Return value

string The proper classes string.

7 calls to ShortcodeBase::addClass()
BootstrapColumnShortcode::process in shortcode_example/src/Plugin/Shortcode/BootstrapColumnShortcode.php
Performs the shortcode processing.
ButtonShortcode::process in shortcode_basic_tags/src/Plugin/Shortcode/ButtonShortcode.php
Performs the shortcode processing.
ClearShortcode::process in shortcode_basic_tags/src/Plugin/Shortcode/ClearShortcode.php
Performs the shortcode processing.
DropcapShortcode::process in shortcode_basic_tags/src/Plugin/Shortcode/DropcapShortcode.php
Performs the shortcode processing.
HighlightShortcode::process in shortcode_basic_tags/src/Plugin/Shortcode/HighlightShortcode.php
Performs the shortcode processing.

... See full list

File

src/Plugin/ShortcodeBase.php, line 197

Class

ShortcodeBase
Provides a base class for Shortcode plugins.

Namespace

Drupal\shortcode\Plugin

Code

public function addClass($classes = '', $new_class = '') {
  $return = [];
  if (is_array($classes)) {
    $return = $classes;
  }
  else {
    $return = explode(' ', Html::escape($classes));
  }
  if ($new_class) {
    $return[] = Html::escape($new_class);
  }
  $return = array_unique($return);
  return implode(' ', $return);
}