瀏覽代碼

Add a mene item to admin parent class to alllow management of child admin; manage comments from post admin

Layton Everson 9 年之前
父節點
當前提交
b90024deb8
共有 1 個文件被更改,包括 26 次插入0 次删除
  1. 26 0
      Resources/doc/reference/architecture.rst

+ 26 - 0
Resources/doc/reference/architecture.rst

@@ -356,6 +356,32 @@ Then, you have to set the CommentAdmin ``parentAssociationMapping`` attribute to
         }
     }
 
+To display the CommentAdmin extend the menu in your ``PostAdmin`` class:
+
+.. code-block:: php
+
+    <?php
+    namespace Sonata\NewsBundle\Admin;
+
+    class PostAdmin extends Admin
+    {
+        // ...
+
+        protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
+        {
+            if (!$childAdmin && !in_array($action, array('edit', 'show'))) { return; }
+
+            $admin = $this->isChild() ? $this->getParent() : $this;
+            $id = $admin->getRequest()->get('id');
+
+            $menu->addChild('Show Post', array('uri' => $admin->generateUrl('show', array('id' => $id))));
+            $menu->addChild('Edit Post', array('uri' => $admin->generateUrl('edit', array('id' => $id))));
+            $menu->addChild('Manage Comments', array(
+                'uri' => $admin->generateUrl('sonata.news.admin.comment.list', array('id' => $id))
+            ));
+        }
+    }
+
 It also possible to set a dot-separated value, like ``post.author``, if your parent and child admins are not directly related.
 
 Be wary that being a child admin is optional, which means that regular routes