protected static function TreeEncodeTrait::decodeTree in Extensible BBCode 4.0.x
Same name and namespace in other branches
- 8.3 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_standardCode
protected static function decodeTree(string $cell, array $children, string $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;
}