Skip to content

Commit

Permalink
Fix code needed for SonataPageBundle (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 authored Aug 26, 2022
1 parent d310b5f commit 9e6d132
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Model/BaseBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,26 @@ public function addChildren(BlockInterface $children): void
$children->setParent($this);
}

public function removeChild(BlockInterface $child): void
{
// NEXT_MAJOR: Remove this condition, children will be a Collection.
if (\is_array($this->children)) {
$key = array_search($child, $this->children, true);

if (false === $key) {
return;
}

unset($this->children[$key]);

return;
}

if ($this->children->contains($child)) {
$this->children->removeElement($child);
}
}

public function getChildren()
{
return $this->children;
Expand Down
1 change: 1 addition & 0 deletions src/Model/BlockInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

/**
* @method void addChild(BlockInterface $child)
* @method void removeChild(BlockInterface $child)
* @method bool hasChild()
*/
interface BlockInterface
Expand Down
3 changes: 3 additions & 0 deletions tests/Util/RecursiveBlockIteratorIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public function testInterface(): void

$block1->addChild($block2);
$block1->addChild($block3);
$block1->removeChild($block3);
$block1->removeChild($block4);
$block1->addChild($block3);

$i = new RecursiveBlockIteratorIterator([$block1, $block4]);

Expand Down

0 comments on commit 9e6d132

Please sign in to comment.