After going through only the same problems with undocumented functions, the only steps you skipped call addChild
and configureSideMenu
in the parent class OrderAdmin.
This solution will create a separate page with sidemenu that will contain lineItems, they will not be embedded in the OrderAdmin form (I'm not sure if this is possible).
There are no routes to configure as SonataAdmin handles this for you.
Here is an example parent admin class using annotations:
namespace YourVendor\YourBundle\Admin; use JMS\DiExtraBundle\Annotation\Service; use JMS\DiExtraBundle\Annotation\Tag; use JMS\DiExtraBundle\Annotation\Inject; use JMS\DiExtraBundle\Annotation\InjectParams; use Knp\Menu\ItemInterface as MenuItemInterface; use Sonata\AdminBundle\Admin\Admin; use Sonata\AdminBundle\Admin\AdminInterface; class OrderAdmin extends Admin { public function __construct($code, $class, $baseControllerName, $lineItems) { parent::__construct($code, $class, $baseControllerName); $this->addChild($lineItems); } 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 Order', array('uri' => $admin->generateUrl('show', array('id' => $id)))); $menu->addChild('Edit Order', array('uri' => $admin->generateUrl('edit', array('id' => $id)))); $menu->addChild('Line items', array('uri' => $admin->generateUrl('sonata.admin.line_item.list', array('id' => $id)))); } }
If you use XML or YML for your services, you probably will not need the __construct
method, as addChild
calls can go into the service definition.
At the time of writing, there is an open problem with the JMS DiExtra Bundle with a pull request for the selected @Admin annotation, which can also avoid this requirement. It was quiet for a couple of weeks.
Barry
source share