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

Commit 4becdeb

Browse files
committed
Merge pull request #187 from symfony-cmf/child-cleanup
cleanup parent interface handling
2 parents 03c1fe5 + 2763f23 commit 4becdeb

File tree

10 files changed

+108
-68
lines changed

10 files changed

+108
-68
lines changed

Admin/MenuAdmin.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
class MenuAdmin extends AbstractMenuNodeAdmin
1818
{
19-
2019
/**
2120
* {@inheritDoc}
2221
*/

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
1.1.0-RC3
5+
---------
6+
7+
* **2014-04-30**: Moved parent handling from MenuNodeBase to MenuNode to conform
8+
with the CMF rules of base models being the minimal model. HierarchyInterface
9+
on PHPCR MenuNode.
10+
411
1.1.0-RC2
512
---------
613

@@ -14,8 +21,8 @@ Changelog
1421
skip building the menu item altogether.
1522

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

2027
* **2014-01-10**: The PhpcrMenuProvider now attempts to prefetch the whole menu
2128
node tree to reduce the number of requests to the PHPCR storage. You can

Doctrine/Phpcr/Menu.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,30 @@
1111

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

14+
use Doctrine\ODM\PHPCR\HierarchyInterface;
1415
use Symfony\Cmf\Bundle\MenuBundle\Model\Menu as BaseMenu;
1516

16-
class Menu extends BaseMenu
17+
class Menu extends BaseMenu implements HierarchyInterface
1718
{
19+
/**
20+
* Set the parent of this menu node
21+
*
22+
* @param $parent MenuNode - Parent node
23+
*
24+
* @return MenuNode - this instance
25+
*/
26+
public function setParentDocument($parent)
27+
{
28+
return $this->setParentObject($parent);
29+
}
30+
31+
/**
32+
* Returns the parent of this menu node
33+
*
34+
* @return object
35+
*/
36+
public function getParentDocument()
37+
{
38+
return $this->getParentObject();
39+
}
1840
}

Doctrine/Phpcr/MenuNode.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,30 @@
1111

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

14+
use Doctrine\ODM\PHPCR\HierarchyInterface;
1415
use Symfony\Cmf\Bundle\MenuBundle\Model\MenuNode as BaseMenuNode;
1516

16-
class MenuNode extends BaseMenuNode
17+
class MenuNode extends BaseMenuNode implements HierarchyInterface
1718
{
19+
/**
20+
* Set the parent of this menu node
21+
*
22+
* @param $parent MenuNode - Parent node
23+
*
24+
* @return MenuNode - this instance
25+
*/
26+
public function setParentDocument($parent)
27+
{
28+
return $this->setParentObject($parent);
29+
}
30+
31+
/**
32+
* Returns the parent of this menu node
33+
*
34+
* @return object
35+
*/
36+
public function getParentDocument()
37+
{
38+
return $this->getParentObject();
39+
}
1840
}

Model/MenuNode.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

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

14+
use Symfony\Cmf\Bundle\CoreBundle\Model\ChildInterface;
1415
use Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface;
1516
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishTimePeriodInterface;
1617
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishableInterface;
@@ -32,8 +33,16 @@
3233
class MenuNode extends MenuNodeBase implements
3334
TranslatableInterface,
3435
PublishTimePeriodInterface,
35-
PublishableInterface
36+
PublishableInterface,
37+
ChildInterface
3638
{
39+
/**
40+
* Parent menu node.
41+
*
42+
* @var mixed
43+
*/
44+
protected $parent;
45+
3746
/**
3847
* @var string
3948
*/
@@ -67,6 +76,40 @@ class MenuNode extends MenuNodeBase implements
6776
*/
6877
protected $publishEndDate;
6978

79+
/**
80+
* {@inheritDoc}
81+
*/
82+
public function setParentObject($parent)
83+
{
84+
$this->parent = $parent;
85+
86+
return $this;
87+
}
88+
89+
/**
90+
* {@inheritDoc}
91+
*/
92+
public function getParentObject()
93+
{
94+
return $this->parent;
95+
}
96+
97+
/**
98+
* @deprecated use setParentObject instead.
99+
*/
100+
public function setParent($parent)
101+
{
102+
return $this->setParentObject($parent);
103+
}
104+
105+
/**
106+
* @deprecated use getParentObject instead.
107+
*/
108+
public function getParent()
109+
{
110+
return $this->getParentObject();
111+
}
112+
70113
/**
71114
* @return string the loaded locale of this menu node
72115
*/

Model/MenuNodeBase.php

Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* @author Uwe Jäger <[email protected]>
2424
* @author Daniel Leech <[email protected]>
2525
*/
26-
class MenuNodeBase implements NodeInterface, ChildInterface
26+
class MenuNodeBase implements NodeInterface
2727
{
2828
/**
2929
* Id of this menu node.
@@ -32,13 +32,6 @@ class MenuNodeBase implements NodeInterface, ChildInterface
3232
*/
3333
protected $id;
3434

35-
/**
36-
* Parent node.
37-
*
38-
* @var mixed
39-
*/
40-
protected $parent;
41-
4235
/**
4336
* Node name.
4437
*
@@ -154,7 +147,7 @@ public function __construct($name = null)
154147
}
155148

156149
/**
157-
* Return ID (PHPCR path) of this menu node
150+
* Return ID of this menu node
158151
*
159152
* @return string
160153
*/
@@ -164,9 +157,7 @@ public function getId()
164157
}
165158

166159
/**
167-
* Sets ID (PHPCR path) of this menu node
168-
*
169-
* The recommended way is to use setParent and setName rather than setId.
160+
* Sets ID of this menu node.
170161
*
171162
* @param $id string
172163
*
@@ -179,48 +170,6 @@ public function setId($id)
179170
return $this;
180171
}
181172

182-
/**
183-
* @deprecated Use setParentDocument instead.
184-
*/
185-
public function setParent($parent)
186-
{
187-
$this->parent = $parent;
188-
189-
return $this;
190-
}
191-
192-
/**
193-
* @deprecated Use getParentDocument instead.
194-
*/
195-
public function getParent()
196-
{
197-
return $this->parent;
198-
}
199-
200-
/**
201-
* Set the parent of this menu node
202-
*
203-
* @param $parent MenuNode - Parent node
204-
*
205-
* @return MenuNode - this instance
206-
*/
207-
public function setParentDocument($parent)
208-
{
209-
$this->parent = $parent;
210-
211-
return $this;
212-
}
213-
214-
/**
215-
* Returns the parent of this menu node
216-
*
217-
* @return object
218-
*/
219-
public function getParentDocument()
220-
{
221-
return $this->parent;
222-
}
223-
224173
/**
225174
* {@inheritDoc}
226175
*/
@@ -284,9 +233,9 @@ public function setLabel($label)
284233
}
285234

286235
/**
287-
* Return the URI
236+
* Return the URI this menu node points to.
288237
*
289-
* @return $uri string
238+
* @return string URI
290239
*/
291240
public function getUri()
292241
{

Resources/config/doctrine-model/MenuNode.phpcr.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
name="Symfony\Cmf\Bundle\MenuBundle\Model\MenuNode"
1010
translator="attribute"
1111
>
12+
<parent-document name="parent"/>
1213

1314
<locale name="locale"/>
1415

Resources/config/doctrine-model/MenuNodeBase.phpcr.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99
name="Symfony\Cmf\Bundle\MenuBundle\Model\MenuNodeBase"
1010
>
1111

12-
<id name="id">
13-
<generator strategy="PARENT"/>
14-
</id>
12+
<id name="id"/>
1513
<nodename name="name"/>
16-
<parent-document name="parent"/>
1714

1815
<field name="label" type="string"/>
1916
<field name="uri" type="string" nullable="true"/>

Tests/Resources/Document/Content.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* @PHPCR\Document(referenceable=true)
2626
*/
27-
class Content implements MenuNodeReferrersInterface, RouteReferrersReadInterface, ChildInterface
27+
class Content implements MenuNodeReferrersInterface, RouteReferrersReadInterface
2828
{
2929
/**
3030
* @PHPCR\Id(strategy="assigned")

Tests/Resources/app/config/test-services.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
class="Symfony\Cmf\Bundle\MenuBundle\Voter\RequestParentContentIdentityVoter">
2424
<argument>contentDocument</argument>
2525
<argument>Symfony\Cmf\Bundle\MenuBundle\Tests\Resources\Document\Post</argument>
26+
<call method="setRequest"><argument type="service" id="request" on-invalid="null" strict="false"/></call>
2627
<tag name="cmf_menu.voter"/>
27-
<tag name="cmf_request_aware"/>
2828
</service>
2929

3030

0 commit comments

Comments
 (0)