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

Commit

Permalink
Merge pull request #187 from symfony-cmf/child-cleanup
Browse files Browse the repository at this point in the history
cleanup parent interface handling
  • Loading branch information
dbu committed Apr 30, 2014
2 parents 03c1fe5 + 2763f23 commit 4becdeb
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 68 deletions.
1 change: 0 additions & 1 deletion Admin/MenuAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

class MenuAdmin extends AbstractMenuNodeAdmin
{

/**
* {@inheritDoc}
*/
Expand Down
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

1.1.0-RC3
---------

* **2014-04-30**: Moved parent handling from MenuNodeBase to MenuNode to conform
with the CMF rules of base models being the minimal model. HierarchyInterface
on PHPCR MenuNode.

1.1.0-RC2
---------

Expand All @@ -14,8 +21,8 @@ Changelog
skip building the menu item altogether.

* **2014-03-24**: setParent() and getParent() are now deprecated.
Use setParentDocument() and getParentDocument() instead.
Moreover, you should now enable the ChildExtension from the CoreBundle.
Use setParentObject() and getParentObject() instead.
When using Sonata admin, you can enable the ChildExtension from the CoreBundle.

* **2014-01-10**: The PhpcrMenuProvider now attempts to prefetch the whole menu
node tree to reduce the number of requests to the PHPCR storage. You can
Expand Down
24 changes: 23 additions & 1 deletion Doctrine/Phpcr/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,30 @@

namespace Symfony\Cmf\Bundle\MenuBundle\Doctrine\Phpcr;

use Doctrine\ODM\PHPCR\HierarchyInterface;
use Symfony\Cmf\Bundle\MenuBundle\Model\Menu as BaseMenu;

class Menu extends BaseMenu
class Menu extends BaseMenu implements HierarchyInterface
{
/**
* Set the parent of this menu node
*
* @param $parent MenuNode - Parent node
*
* @return MenuNode - this instance
*/
public function setParentDocument($parent)
{
return $this->setParentObject($parent);
}

/**
* Returns the parent of this menu node
*
* @return object
*/
public function getParentDocument()
{
return $this->getParentObject();
}
}
24 changes: 23 additions & 1 deletion Doctrine/Phpcr/MenuNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,30 @@

namespace Symfony\Cmf\Bundle\MenuBundle\Doctrine\Phpcr;

use Doctrine\ODM\PHPCR\HierarchyInterface;
use Symfony\Cmf\Bundle\MenuBundle\Model\MenuNode as BaseMenuNode;

class MenuNode extends BaseMenuNode
class MenuNode extends BaseMenuNode implements HierarchyInterface
{
/**
* Set the parent of this menu node
*
* @param $parent MenuNode - Parent node
*
* @return MenuNode - this instance
*/
public function setParentDocument($parent)
{
return $this->setParentObject($parent);
}

/**
* Returns the parent of this menu node
*
* @return object
*/
public function getParentDocument()
{
return $this->getParentObject();
}
}
45 changes: 44 additions & 1 deletion Model/MenuNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Cmf\Bundle\MenuBundle\Model;

use Symfony\Cmf\Bundle\CoreBundle\Model\ChildInterface;
use Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface;
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishTimePeriodInterface;
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishableInterface;
Expand All @@ -32,8 +33,16 @@
class MenuNode extends MenuNodeBase implements
TranslatableInterface,
PublishTimePeriodInterface,
PublishableInterface
PublishableInterface,
ChildInterface
{
/**
* Parent menu node.
*
* @var mixed
*/
protected $parent;

/**
* @var string
*/
Expand Down Expand Up @@ -67,6 +76,40 @@ class MenuNode extends MenuNodeBase implements
*/
protected $publishEndDate;

/**
* {@inheritDoc}
*/
public function setParentObject($parent)
{
$this->parent = $parent;

return $this;
}

/**
* {@inheritDoc}
*/
public function getParentObject()
{
return $this->parent;
}

/**
* @deprecated use setParentObject instead.
*/
public function setParent($parent)
{
return $this->setParentObject($parent);
}

/**
* @deprecated use getParentObject instead.
*/
public function getParent()
{
return $this->getParentObject();
}

/**
* @return string the loaded locale of this menu node
*/
Expand Down
61 changes: 5 additions & 56 deletions Model/MenuNodeBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @author Uwe Jäger <uwej711@googlemail.com>
* @author Daniel Leech <daniel@dantleech.com>
*/
class MenuNodeBase implements NodeInterface, ChildInterface
class MenuNodeBase implements NodeInterface
{
/**
* Id of this menu node.
Expand All @@ -32,13 +32,6 @@ class MenuNodeBase implements NodeInterface, ChildInterface
*/
protected $id;

/**
* Parent node.
*
* @var mixed
*/
protected $parent;

/**
* Node name.
*
Expand Down Expand Up @@ -154,7 +147,7 @@ public function __construct($name = null)
}

/**
* Return ID (PHPCR path) of this menu node
* Return ID of this menu node
*
* @return string
*/
Expand All @@ -164,9 +157,7 @@ public function getId()
}

/**
* Sets ID (PHPCR path) of this menu node
*
* The recommended way is to use setParent and setName rather than setId.
* Sets ID of this menu node.
*
* @param $id string
*
Expand All @@ -179,48 +170,6 @@ public function setId($id)
return $this;
}

/**
* @deprecated Use setParentDocument instead.
*/
public function setParent($parent)
{
$this->parent = $parent;

return $this;
}

/**
* @deprecated Use getParentDocument instead.
*/
public function getParent()
{
return $this->parent;
}

/**
* Set the parent of this menu node
*
* @param $parent MenuNode - Parent node
*
* @return MenuNode - this instance
*/
public function setParentDocument($parent)
{
$this->parent = $parent;

return $this;
}

/**
* Returns the parent of this menu node
*
* @return object
*/
public function getParentDocument()
{
return $this->parent;
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -284,9 +233,9 @@ public function setLabel($label)
}

/**
* Return the URI
* Return the URI this menu node points to.
*
* @return $uri string
* @return string URI
*/
public function getUri()
{
Expand Down
1 change: 1 addition & 0 deletions Resources/config/doctrine-model/MenuNode.phpcr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
name="Symfony\Cmf\Bundle\MenuBundle\Model\MenuNode"
translator="attribute"
>
<parent-document name="parent"/>

<locale name="locale"/>

Expand Down
5 changes: 1 addition & 4 deletions Resources/config/doctrine-model/MenuNodeBase.phpcr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
name="Symfony\Cmf\Bundle\MenuBundle\Model\MenuNodeBase"
>

<id name="id">
<generator strategy="PARENT"/>
</id>
<id name="id"/>
<nodename name="name"/>
<parent-document name="parent"/>

<field name="label" type="string"/>
<field name="uri" type="string" nullable="true"/>
Expand Down
2 changes: 1 addition & 1 deletion Tests/Resources/Document/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* @PHPCR\Document(referenceable=true)
*/
class Content implements MenuNodeReferrersInterface, RouteReferrersReadInterface, ChildInterface
class Content implements MenuNodeReferrersInterface, RouteReferrersReadInterface
{
/**
* @PHPCR\Id(strategy="assigned")
Expand Down
2 changes: 1 addition & 1 deletion Tests/Resources/app/config/test-services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
class="Symfony\Cmf\Bundle\MenuBundle\Voter\RequestParentContentIdentityVoter">
<argument>contentDocument</argument>
<argument>Symfony\Cmf\Bundle\MenuBundle\Tests\Resources\Document\Post</argument>
<call method="setRequest"><argument type="service" id="request" on-invalid="null" strict="false"/></call>
<tag name="cmf_menu.voter"/>
<tag name="cmf_request_aware"/>
</service>


Expand Down

0 comments on commit 4becdeb

Please sign in to comment.