|
5 | 5 | use Sonata\AdminBundle\Form\FormMapper; |
6 | 6 | use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin; |
7 | 7 | use Symfony\Cmf\Bundle\MenuBundle\Model\MenuNode; |
| 8 | +use Symfony\Cmf\Bundle\MenuBundle\Model\Menu; |
8 | 9 | use Knp\Menu\ItemInterface as MenuItemInterface; |
9 | 10 | use Doctrine\Common\Util\ClassUtils; |
10 | 11 |
|
@@ -41,71 +42,29 @@ public function buildBreadcrumbs($action, MenuItemInterface $menu = null) |
41 | 42 | return $menuNodeNode; |
42 | 43 | } |
43 | 44 |
|
44 | | - $menuDoc = $this->getMenuForSubject($this->getSubject()); |
| 45 | + $parentDoc = $this->getSubject()->getParent(); |
45 | 46 | $pool = $this->getConfigurationPool(); |
46 | | - $menuAdmin = $pool->getAdminByClass( |
47 | | - ClassUtils::getClass($menuDoc) |
| 47 | + $parentAdmin = $pool->getAdminByClass( |
| 48 | + ClassUtils::getClass($parentDoc) |
48 | 49 | ); |
49 | | - $menuAdmin->setSubject($menuDoc); |
50 | | - $menuEditNode = $menuAdmin->buildBreadcrumbs($action, $menu); |
51 | | - if ($menuAdmin->isGranted('EDIT' && $menuAdmin->hasRoute('edit'))) { |
52 | | - $menuEditNode->setUri( |
53 | | - $menuAdmin->generateUrl('edit', array( |
54 | | - 'id' => $this->getUrlsafeIdentifier($menuDoc) |
| 50 | + |
| 51 | + if (null === $parentAdmin) { |
| 52 | + return $menuNodeNode; |
| 53 | + } |
| 54 | + |
| 55 | + $parentAdmin->setSubject($parentDoc); |
| 56 | + $parentEditNode = $parentAdmin->buildBreadcrumbs($action, $menu); |
| 57 | + if ($parentAdmin->isGranted('EDIT' && $parentAdmin->hasRoute('edit'))) { |
| 58 | + $parentEditNode->setUri( |
| 59 | + $parentAdmin->generateUrl('edit', array( |
| 60 | + 'id' => $this->getUrlsafeIdentifier($parentDoc) |
55 | 61 | )) |
56 | 62 | ); |
57 | 63 | } |
58 | 64 |
|
59 | 65 | $menuNodeNode->setParent(null); |
60 | | - $current = $menuEditNode->addChild($menuNodeNode); |
| 66 | + $current = $parentEditNode->addChild($menuNodeNode); |
61 | 67 |
|
62 | 68 | return $current; |
63 | 69 | } |
64 | | - |
65 | | - protected function getMenuForSubject(MenuNode $subject) |
66 | | - { |
67 | | - $id = $subject->getId(); |
68 | | - |
69 | | - $menuId = $this->getMenuIdForNodeId($id); |
70 | | - |
71 | | - $menu = $this->modelManager->find(null, $menuId); |
72 | | - |
73 | | - return $menu; |
74 | | - } |
75 | | - |
76 | | - protected function getMenuIdForNodeId($id) |
77 | | - { |
78 | | - // I wonder if this could be simplified in Phpcr/PathHelper |
79 | | - // |
80 | | - // $relPath = PathHelper::removeBasePath($this->menuRoot, $id); |
81 | | - // $menuId = PathHelper:splicePath($relPath, 0, 1); |
82 | | - |
83 | | - if (0 !== strpos($id, $this->menuRoot)) { |
84 | | - throw new \InvalidArgumentException(sprintf( |
85 | | - 'Cannot find base path "%s" in menu node ID "%s"', $this->menuRoot, $id |
86 | | - )); |
87 | | - } |
88 | | - |
89 | | - $relPath = substr($id, strlen($this->menuRoot) + 1); |
90 | | - $parts = explode('/', $relPath); |
91 | | - |
92 | | - if (count($parts) == 0) { |
93 | | - throw new \InvalidArgumentException(sprintf( |
94 | | - 'ID for menu node "%s" may not be the same as root path "%s"', |
95 | | - $id, $this->menuRoot |
96 | | - )); |
97 | | - } |
98 | | - |
99 | | - if (count($parts) == 1) { |
100 | | - throw new \InvalidArgumentException(sprintf( |
101 | | - 'MenuNode "%s" may not hold the position reserved for a Menu.', |
102 | | - $id |
103 | | - )); |
104 | | - } |
105 | | - |
106 | | - $first = $parts[0]; |
107 | | - $menuId = sprintf('%s/%s', $this->menuRoot, $first); |
108 | | - |
109 | | - return $menuId; |
110 | | - } |
111 | 70 | } |
0 commit comments