public insertAfter ( |
||
$node | the child node of this node's children the new node will be inserted after | |
$newNode | the new node that will be inserted after the first node |
public function insertAfter(Node $node, Node $newNode)
{
$index = $this->indexOf($node);
if ($index === false) {
return $this->append($newNode);
}
array_splice($this->children, $index + 1, 0, [$newNode]);
$newNode->parent = $this;
return $this;
}
/** * Stacks blocks into each other. * * The first block found is always the container, * all other blocks either to append, replace or prepend * to/the first block. * * @param Node $node the block node to handle * * @return $this */ protected function handleBlock(Node $node) { if (!$node->name || $node->mode === 'ignore') { //Will be handled through compileBlock when the loop encounters it return $this; } //Find all other blocks with that name foreach ($this->blocks as $block) { if ($block === $node || $block->name !== $node->name) { continue; } $mode = $block->mode; //detach from parent $block->parent->remove($block); switch ($mode) { default: /** @noinspection PhpMissingBreakStatementInspection */ /** @noinspection PhpMissingBreakStatementInspection */ case 'replace': $node->children = []; //WANTED FALLTHROUGH! //WANTED FALLTHROUGH! case 'append': //Append to master block foreach ($block->children as $child) { $block->remove($child); $node->append($child); } break; case 'prepend': $last = null; foreach ($block->children as $child) { $block->remove($child); if (!$last) { $node->prepend($child); $last = $child; continue; } $node->insertAfter($last, $child); $last = $child; } break; } $block->mode = 'ignore'; } return $this; }