You are here

public static function XBBCodeFilter::doPrepare in Extensible BBCode 4.0.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/Filter/XBBCodeFilter.php \Drupal\xbbcode\Plugin\Filter\XBBCodeFilter::doPrepare()

Recursively apply source transformations to each tag element.

Parameters

\Drupal\xbbcode\Parser\Tree\ElementInterface $node: The parse tree.

Return value

string The fully prepared source.

1 call to XBBCodeFilter::doPrepare()
XBBCodeFilter::prepare in src/Plugin/Filter/XBBCodeFilter.php
Prepares the text for processing.

File

src/Plugin/Filter/XBBCodeFilter.php, line 262

Class

XBBCodeFilter
Provides a filter that converts BBCode to HTML.

Namespace

Drupal\xbbcode\Plugin\Filter

Code

public static function doPrepare(ElementInterface $node) : string {
  if ($node instanceof NodeElementInterface) {
    $content = [];
    foreach ($node
      ->getChildren() as $child) {
      $content[] = static::doPrepare($child);
    }
    $content = implode('', $content);
    if ($node instanceof TagElementInterface) {
      $processor = $node
        ->getProcessor();
      if ($processor instanceof TagPluginInterface) {
        $content = $processor
          ->prepare($content, $node);
      }
      return "[{$node->getOpeningName()}{$node->getArgument()}]{$content}[/{$node->getClosingName()}]";
    }
    return $content;
  }
  return $node
    ->render();
}