abstract class NodeElement in Extensible BBCode 4.0.x
Same name and namespace in other branches
- 8.3 src/Parser/Tree/NodeElement.php \Drupal\xbbcode\Parser\Tree\NodeElement
A node element contains other elements.
Hierarchy
- class \Drupal\xbbcode\Parser\Tree\NodeElement implements NodeElementInterface
Expanded class hierarchy of NodeElement
File
- src/
Parser/ Tree/ NodeElement.php, line 8
Namespace
Drupal\xbbcode\Parser\TreeView source
abstract class NodeElement implements NodeElementInterface {
/**
* The children of this node.
*
* @var \Drupal\xbbcode\Parser\Tree\ElementInterface[]
*/
protected $children = [];
/**
* The rendered children of this node.
*
* @var \Drupal\xbbcode\Parser\Tree\OutputElementInterface[]
*/
protected $output;
/**
* {@inheritdoc}
*/
public function append(ElementInterface $element) : void {
$this->children[] = $element;
}
/**
* {@inheritdoc}
*/
public function getChildren() : array {
return $this->children;
}
/**
* {@inheritdoc}
*/
public function getContent() : string {
return implode('', $this
->getRenderedChildren());
}
/**
* {@inheritdoc}
*/
public function getRenderedChildren($force_render = TRUE) : array {
if (!$force_render) {
return $this->output ?? [];
}
if ($this->output === NULL) {
$this->output = [];
foreach ($this->children as $child) {
$this->output[] = $child
->render();
}
}
return $this->output;
}
/**
* {@inheritdoc}
*/
public function getDescendants() : \Iterator {
foreach ($this->children as $child) {
(yield $child);
if ($child instanceof NodeElementInterface) {
yield from $child
->getDescendants();
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ElementInterface:: |
public | function | Render this element to a string. | 4 |
NodeElement:: |
protected | property | The children of this node. | |
NodeElement:: |
protected | property | The rendered children of this node. | |
NodeElement:: |
public | function |
Append an element to the children of this element. Overrides NodeElementInterface:: |
|
NodeElement:: |
public | function |
Get all children of the element. Overrides NodeElementInterface:: |
|
NodeElement:: |
public | function |
Retrieve the rendered content of the element. Overrides NodeElementInterface:: |
|
NodeElement:: |
public | function |
Retrieve the descendants of the node. Overrides NodeElementInterface:: |
|
NodeElement:: |
public | function |
Retrieve the rendered output of each child. Overrides NodeElementInterface:: |