Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 28769ad

Browse files
committed
Merge pull request #183 from uwej711/fix_children_init
add removeChild and init children with Collection
2 parents 5e72910 + 15094f5 commit 28769ad

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

Model/MenuNodeBase.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace Symfony\Cmf\Bundle\MenuBundle\Model;
1414

15+
use Doctrine\Common\Collections\ArrayCollection;
16+
use Doctrine\Common\Collections\Collection;
1517
use Knp\Menu\NodeInterface;
1618
use Symfony\Cmf\Bundle\CoreBundle\Model\ChildInterface;
1719

@@ -48,9 +50,9 @@ class MenuNodeBase implements NodeInterface, ChildInterface
4850
/**
4951
* Child menu nodes
5052
*
51-
* @var MenuNode[]
53+
* @var Collection
5254
*/
53-
protected $children = array();
55+
protected $children;
5456

5557
/**
5658
* Menu label.
@@ -149,6 +151,7 @@ class MenuNodeBase implements NodeInterface, ChildInterface
149151
public function __construct($name = null)
150152
{
151153
$this->name = $name;
154+
$this->children = new ArrayCollection();
152155
}
153156

154157
/**
@@ -443,6 +446,16 @@ public function addChild(MenuNode $child)
443446
return $child;
444447
}
445448

449+
/**
450+
* Remove a child menu node
451+
*
452+
* @param MenuNode $child
453+
*/
454+
public function removeChild(MenuNode $child)
455+
{
456+
$this->children->removeElement($child);
457+
}
458+
446459
/**
447460
* Gets the route parameters.
448461
*

Tests/Functional/Doctrine/Phpcr/MenuNodeTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,14 @@ public function testMenuNode()
147147

148148
$menuNode = $this->dm->findTranslation(null, '/test/test-node', 'fr');
149149
$this->assertEquals('fr', $menuNode->getLocale());
150+
151+
$child = $this->dm->find(null, '/test/test-node/child1');
152+
$menuNode = $child->getParent();
153+
$this->assertCount(1, $menuNode->getChildren());
154+
$menuNode->removeChild($child);
155+
$this->dm->flush();
156+
$this->dm->clear();
157+
$menuNode = $this->dm->find(null, '/test/test-node');
158+
$this->assertCount(0, $menuNode->getChildren());
150159
}
151160
}

0 commit comments

Comments
 (0)