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

Commit 00b2031

Browse files
committed
Merge pull request #133 from symfony-cmf/improve-admin
a root menu document can not be added anywhere in the tree, only at the root
2 parents 1693cb5 + 791a341 commit 00b2031

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

Admin/AbstractMenuNodeAdmin.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,13 @@ protected function isSubjectNotNew()
3434
return $this->hasSubject() && null !== $this->getSubject()->getId();
3535
}
3636

37+
/**
38+
* {@inheritDoc}
39+
*/
3740
protected function configureFormFields(FormMapper $formMapper)
3841
{
3942
$formMapper
4043
->with('form.group_general')
41-
->add(
42-
'parent',
43-
'doctrine_phpcr_odm_tree',
44-
array('root_node' => $this->menuRoot, 'choice_list' => array(), 'select_root_node' => true)
45-
)
4644
->add('name', 'text',
4745
$this->isSubjectNotNew() ? array(
4846
'attr' => array('readonly' => 'readonly')

Admin/MenuAdmin.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
namespace Symfony\Cmf\Bundle\MenuBundle\Admin;
44

55
use Sonata\AdminBundle\Form\FormMapper;
6+
use Symfony\Cmf\Bundle\MenuBundle\Doctrine\Phpcr\Menu;
67

78
class MenuAdmin extends AbstractMenuNodeAdmin
89
{
910
protected $baseRouteName = 'cmf_menu';
1011
protected $baseRoutePattern = '/cmf/menu/menu';
1112

13+
/**
14+
* {@inheritDoc}
15+
*/
1216
protected function configureFormFields(FormMapper $formMapper)
1317
{
1418
parent::configureFormFields($formMapper);
@@ -30,4 +34,13 @@ protected function configureFormFields(FormMapper $formMapper)
3034
;
3135
}
3236
}
37+
38+
public function getNewInstance()
39+
{
40+
/** @var $new Menu */
41+
$new = parent::getNewInstance();
42+
$new->setParent($this->getModelManager()->find(null, $this->menuRoot));
43+
44+
return $new;
45+
}
3346
}

Admin/MenuNodeAdmin.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Symfony\Cmf\Bundle\MenuBundle\Admin;
44

5+
use Sonata\AdminBundle\Form\FormMapper;
56
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;
67
use Symfony\Cmf\Bundle\MenuBundle\Model\MenuNode;
78
use Knp\Menu\ItemInterface as MenuItemInterface;
@@ -12,6 +13,23 @@ class MenuNodeAdmin extends AbstractMenuNodeAdmin
1213
protected $baseRouteName = 'cmf_menu_menunode';
1314
protected $baseRoutePattern = '/cmf/menu/menunode';
1415

16+
/**
17+
* {@inheritDoc}
18+
*/
19+
protected function configureFormFields(FormMapper $formMapper)
20+
{
21+
$formMapper
22+
->with('form.group_general')
23+
->add(
24+
'parent',
25+
'doctrine_phpcr_odm_tree',
26+
array('root_node' => $this->menuRoot, 'choice_list' => array(), 'select_root_node' => true)
27+
)
28+
->end()
29+
;
30+
parent::configureFormFields($formMapper);
31+
}
32+
1533
/**
1634
* {@inheritDoc}
1735
*/

Tests/WebTest/Admin/MenuAdminTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public function testMenuCreate()
5050
$actionUrl = $node->getAttribute('action');
5151
$uniqId = substr(strchr($actionUrl, '='), 1);
5252

53-
$form[$uniqId.'[parent]'] = '/test/menus';
5453
$form[$uniqId.'[name]'] = 'foo-test';
5554
$form[$uniqId.'[label]'] = 'Foo Test';
5655

Tests/WebTest/Admin/MenuNodeAdminTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function setUp()
1616

1717
public function testEdit()
1818
{
19-
$crawler = $this->client->request('GET', '/admin/cmf/menu/menunode/test/menus/test-menu/item-1/edit');
19+
$this->client->request('GET', '/admin/cmf/menu/menunode/test/menus/test-menu/item-1/edit');
2020
$res = $this->client->getResponse();
2121
$this->assertEquals(200, $res->getStatusCode());
2222
}

0 commit comments

Comments
 (0)