From ecb9e9817cafaf41042313a69c3f049a87d548f1 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 14 May 2014 12:41:24 +0200 Subject: [PATCH] removing parent from all but the full phpcr MenuNode document --- CHANGELOG.md | 6 ++++++ Doctrine/Phpcr/Menu.php | 35 +++++++++++++++++++++++++++++++-- Doctrine/Phpcr/MenuNode.php | 34 ++++++++++++++++++++++++++++++-- Doctrine/Phpcr/MenuNodeBase.php | 4 ++-- Model/MenuNodeBase.php | 19 +----------------- 5 files changed, 74 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc195cb7..fd5524de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Changelog ========= +1.1.1 +----- + +* **2014-05-14**: [BC BREAK when extending Model] Removed parent from + MenuNodeBase classes as they are not required by knp menu. + 1.1.0 ----- diff --git a/Doctrine/Phpcr/Menu.php b/Doctrine/Phpcr/Menu.php index c180cec3..a3d637e5 100644 --- a/Doctrine/Phpcr/Menu.php +++ b/Doctrine/Phpcr/Menu.php @@ -12,9 +12,10 @@ namespace Symfony\Cmf\Bundle\MenuBundle\Doctrine\Phpcr; use Doctrine\ODM\PHPCR\HierarchyInterface; -use Symfony\Cmf\Bundle\MenuBundle\Model\Menu as BaseMenu; +use Symfony\Cmf\Bundle\MenuBundle\Model\Menu as ModelMenu; +use Symfony\Cmf\Bundle\MenuBundle\Model\MenuNode as ModelMenuNode; -class Menu extends BaseMenu implements HierarchyInterface +class Menu extends ModelMenu implements HierarchyInterface { /** * Set the parent of this menu node @@ -37,4 +38,34 @@ public function getParentDocument() { return $this->getParentObject(); } + + /** + * Convenience method to set parent and name at the same time. + * + * @param $parent MenuNode + * @param $name string + * + * @return MenuNode - this instance + */ + public function setPosition($parent, $name) + { + $this->setParentObject($parent); + $this->setName($name); + + return $this; + } + + /** + * Add a child menu node, automatically setting the parent node. + * + * @param ModelMenuNode $child + * + * @return MenuNode - The newly added child node. + */ + public function addChild(ModelMenuNode $child) + { + $child->setParentObject($this); + + return parent::addChild($child); + } } diff --git a/Doctrine/Phpcr/MenuNode.php b/Doctrine/Phpcr/MenuNode.php index 6cd99ce5..44f25fbd 100644 --- a/Doctrine/Phpcr/MenuNode.php +++ b/Doctrine/Phpcr/MenuNode.php @@ -12,9 +12,9 @@ namespace Symfony\Cmf\Bundle\MenuBundle\Doctrine\Phpcr; use Doctrine\ODM\PHPCR\HierarchyInterface; -use Symfony\Cmf\Bundle\MenuBundle\Model\MenuNode as BaseMenuNode; +use Symfony\Cmf\Bundle\MenuBundle\Model\MenuNode as ModelMenuNode; -class MenuNode extends BaseMenuNode implements HierarchyInterface +class MenuNode extends ModelMenuNode implements HierarchyInterface { /** * Set the parent of this menu node @@ -37,4 +37,34 @@ public function getParentDocument() { return $this->getParentObject(); } + + /** + * Convenience method to set parent and name at the same time. + * + * @param $parent MenuNode + * @param $name string + * + * @return MenuNode - this instance + */ + public function setPosition($parent, $name) + { + $this->setParentObject($parent); + $this->setName($name); + + return $this; + } + + /** + * Add a child menu node, automatically setting the parent node. + * + * @param MenuNode $child + * + * @return MenuNode - The newly added child node. + */ + public function addChild(ModelMenuNode $child) + { + $child->setParentObject($this); + + return parent::addChild($child); + } } diff --git a/Doctrine/Phpcr/MenuNodeBase.php b/Doctrine/Phpcr/MenuNodeBase.php index 5892b9ab..b6f8c80e 100644 --- a/Doctrine/Phpcr/MenuNodeBase.php +++ b/Doctrine/Phpcr/MenuNodeBase.php @@ -11,8 +11,8 @@ namespace Symfony\Cmf\Bundle\MenuBundle\Doctrine\Phpcr; -use Symfony\Cmf\Bundle\MenuBundle\Model\MenuNodeBase as BaseMenuNodeBase; +use Symfony\Cmf\Bundle\MenuBundle\Model\MenuNodeBase as ModelMenuNodeBase; -class MenuNodeBase extends BaseMenuNodeBase +class MenuNodeBase extends ModelMenuNodeBase { } diff --git a/Model/MenuNodeBase.php b/Model/MenuNodeBase.php index 10956c9b..6e818ef0 100644 --- a/Model/MenuNodeBase.php +++ b/Model/MenuNodeBase.php @@ -192,22 +192,6 @@ public function setName($name) return $this; } - /** - * Convenience method to set parent and name at the same time. - * - * @param $parent MenuNode - * @param $name string - * - * @return MenuNode - this instance - */ - public function setPosition($parent, $name) - { - $this->parent = $parent; - $this->name = $name; - - return $this; - } - /** * Return the label assigned to this menu node * @@ -380,7 +364,7 @@ public function getChildren() } /** - * Add a child menu node, automatically setting the parent node. + * Add a child menu node under this node. * * @param MenuNode $child * @@ -388,7 +372,6 @@ public function getChildren() */ public function addChild(MenuNode $child) { - $child->setParentDocument($this); $this->children[] = $child; return $child;