|
@@ -316,43 +316,83 @@ template files, administration panel title and logo.
|
|
Create child admins
|
|
Create child admins
|
|
-------------------
|
|
-------------------
|
|
|
|
|
|
-Let us say you have a ``PostAdmin`` and a ``CommentAdmin``. You can optionally declare the ``CommentAdmin``
|
|
|
|
-to be a child of the ``PostAdmin``. This will create new routes like, for example, ``/post/{id}/comment/list``,
|
|
|
|
-where the comments will automatically be filtered by post.
|
|
|
|
|
|
+Let us say you have a ``PlaylistAdmin`` and a ``VideoAdmin``. You can optionally declare the ``VideoAdmin``
|
|
|
|
+to be a child of the ``PlaylistAdmin``. This will create new routes like, for example, ``/playlist/{id}/video/list``,
|
|
|
|
+where the videos will automatically be filtered by post.
|
|
|
|
|
|
-To do this, you first need to call the ``addChild`` method in your PostAdmin service configuration :
|
|
|
|
|
|
+To do this, you first need to call the ``addChild`` method in your ``PlaylistAdmin`` service configuration:
|
|
|
|
|
|
.. configuration-block::
|
|
.. configuration-block::
|
|
|
|
|
|
.. code-block:: xml
|
|
.. code-block:: xml
|
|
|
|
|
|
<!-- app/config/config.xml -->
|
|
<!-- app/config/config.xml -->
|
|
- <service id="sonata.news.admin.post" class="Sonata\NewsBundle\Admin\PostAdmin">
|
|
|
|
|
|
+ <service id="sonata.admin.playlist" class="AppBundle\Admin\PlaylistAdmin">
|
|
<!-- ... -->
|
|
<!-- ... -->
|
|
|
|
|
|
<call method="addChild">
|
|
<call method="addChild">
|
|
- <argument type="service" id="sonata.news.admin.comment" />
|
|
|
|
|
|
+ <argument type="service" id="sonata.admin.video" />
|
|
</call>
|
|
</call>
|
|
</service>
|
|
</service>
|
|
|
|
|
|
-Then, you have to set the CommentAdmin ``parentAssociationMapping`` attribute to ``post`` :
|
|
|
|
|
|
+Then, you have to set the VideoAdmin ``parentAssociationMapping`` attribute to ``playlist`` :
|
|
|
|
|
|
.. code-block:: php
|
|
.. code-block:: php
|
|
|
|
|
|
<?php
|
|
<?php
|
|
- namespace Sonata\NewsBundle\Admin;
|
|
|
|
|
|
+
|
|
|
|
+ namespace AppBundle\Admin;
|
|
|
|
|
|
// ...
|
|
// ...
|
|
|
|
|
|
- class CommentAdmin extends AbstractAdmin
|
|
|
|
|
|
+ class VideoAdmin extends AbstractAdmin
|
|
{
|
|
{
|
|
- protected $parentAssociationMapping = 'post';
|
|
|
|
|
|
+ protected $parentAssociationMapping = 'playlist';
|
|
|
|
|
|
// OR
|
|
// OR
|
|
|
|
|
|
public function getParentAssociationMapping()
|
|
public function getParentAssociationMapping()
|
|
{
|
|
{
|
|
- return 'post';
|
|
|
|
|
|
+ return 'playlist';
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+To display the ``VideoAdmin`` extend the menu in your ``PlaylistAdmin`` class:
|
|
|
|
+
|
|
|
|
+.. code-block:: php
|
|
|
|
+
|
|
|
|
+ <?php
|
|
|
|
+
|
|
|
|
+ namespace AppBundle\Admin;
|
|
|
|
+
|
|
|
|
+ use Knp\Menu\ItemInterface as MenuItemInterface;
|
|
|
|
+ use Sonata\AdminBundle\Admin\AbstractAdmin;
|
|
|
|
+ use Sonata\AdminBundle\Admin\AdminInterface;
|
|
|
|
+
|
|
|
|
+ class PlaylistAdmin extends AbstractAdmin
|
|
|
|
+ {
|
|
|
|
+ // ...
|
|
|
|
+
|
|
|
|
+ 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('View Playlist', array('uri' => $admin->generateUrl('show', array('id' => $id))));
|
|
|
|
+
|
|
|
|
+ if ($this->isGranted('EDIT')) {
|
|
|
|
+ $menu->addChild('Edit Playlist', array('uri' => $admin->generateUrl('edit', array('id' => $id))));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ($this->isGranted('LIST')) {
|
|
|
|
+ $menu->addChild('Manage Videos', array(
|
|
|
|
+ 'uri' => $admin->generateUrl('sonata.admin.video.list', array('id' => $id))
|
|
|
|
+ ));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -365,6 +405,7 @@ of them, you may override the ``configureRoutes`` method::
|
|
<?php
|
|
<?php
|
|
namespace Sonata\NewsBundle\Admin;
|
|
namespace Sonata\NewsBundle\Admin;
|
|
|
|
|
|
|
|
+ use Sonata\AdminBundle\Admin\AbstractAdmin;
|
|
use Sonata\AdminBundle\Route\RouteCollection;
|
|
use Sonata\AdminBundle\Route\RouteCollection;
|
|
|
|
|
|
class CommentAdmin extends AbstractAdmin
|
|
class CommentAdmin extends AbstractAdmin
|