You are here

protected static function TreeEncodeTrait::decodeTree in Extensible BBCode 8.3

Same name and namespace in other branches
  1. 4.0.x standard/src/TreeEncodeTrait.php \Drupal\xbbcode_standard\TreeEncodeTrait::decodeTree()

Decode a part of the encoded tree.

Parameters

string $cell: The text (or part of the text) of the encoded tree.

array $children: The children which were previously encoded.

string $token: The token used as a placeholder.

Return value

\Drupal\xbbcode\Parser\Tree\TagElement A pseudo-tag element (empty name) containing the part of the tree represented by $cell.

2 calls to TreeEncodeTrait::decodeTree()
ListTagPlugin::splitContent in standard/src/Plugin/XBBCode/ListTagPlugin.php
Split the tag's children into list items.
TableTagPlugin::tabulateTree in standard/src/Plugin/XBBCode/TableTagPlugin.php
Helper that turns a parse tree into a table of cells.

File

standard/src/TreeEncodeTrait.php, line 77

Class

TreeEncodeTrait
Static helper functions for tag plugins that parse their top-level text.

Namespace

Drupal\xbbcode_standard

Code

protected static function decodeTree($cell, array $children, $token) : TagElement {
  $items = preg_split("/{tag:{$token}:(\\d+)}/", $cell, NULL, PREG_SPLIT_DELIM_CAPTURE);
  $tree = new TagElement('', '', '');
  foreach ($items as $i => $item) {
    if ($item !== '') {
      $tree
        ->append($i % 2 ? $children[$item] : new TextElement($item));
    }
  }
  return $tree;
}