You are here

protected function ShortcodeService::processTag in Shortcode 2.0.x

Same name and namespace in other branches
  1. 8 src/ShortcodeService.php \Drupal\shortcode\ShortcodeService::processTag()

Regular Expression callable for do_shortcode() for calling Shortcode hook.

See for details of the match array contents.

Parameters

array $m: Regular expression match array.

0 - the full tag text? 1/5 - An extra [ or ] to allow for escaping shortcodes with double [[]] 2 - The Shortcode name 3 - The Shortcode argument list 4 - The content of a Shortcode when it wraps some content.

array $enabled_shortcodes: Array of enabled shortcodes for the active text format.

Return value

string|false FALSE on failure.

1 call to ShortcodeService::processTag()
ShortcodeService::process in src/ShortcodeService.php
Processes the Shortcodes according to the text and the text format.

File

src/ShortcodeService.php, line 415

Class

ShortcodeService
Provide the ShortCode service.

Namespace

Drupal\shortcode

Code

protected function processTag(array $m, array $enabled_shortcodes) {
  $shortcode_token = $m[2];
  $shortcode = NULL;
  if (isset($enabled_shortcodes[$shortcode_token])) {
    $shortcode_id = $enabled_shortcodes[$shortcode_token]['id'];
    $shortcode = $this
      ->getShortcodePlugin($shortcode_id);
  }

  // If shortcode does not exist or is not enabled, return input sans tokens.
  if (empty($shortcode)) {

    // This is an enclosing tag, means extra parameter is present.
    if (!is_null($m[4])) {
      return $m[1] . $m[4] . $m[5];
    }
    else {
      return $m[1] . $m[5];
    }
  }

  // Process if shortcode exists and enabled.
  $attr = $this
    ->parseAttrs($m[3]);
  return $m[1] . $shortcode
    ->process($attr, $m[4]) . $m[5];
}