There is a difficulty while integrating FOSMessageBundle into SonataAdminBundle. I want FOSMessage to be under Sonata's menu. So I made FOSMessage's basic layout to extend standard sonata layout:
{% extends "::standard_layout.html.twig" %}
The problem is that sonata menu needs some extra twig variables, which are generated in its CoreController based controllers:
array(
'base_template' => $this->getBaseTemplate(),
'admin_pool' => $this->container->get('sonata.admin.pool'),
'blocks' => $this->container->getParameter('sonata.admin.configuration.dashboard_blocks')
);
Is there an easy way of providing external (FOSMessageBundle's) templates with these variables?
Found an appropriate solution.
In standard Sonata layout replace all menu stuff and put it into isolated template in simple controller:
{% render(controller('MyBundle:SonataMenu:index')) %}
The controller:
namespace MyBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sonata\AdminBundle\Controller\CoreController;
class SonataMenuController extends CoreController
{
/**
* @Route("/admin/sonata_menu", name="sonata_menu")
* @Template()
*/
public function indexAction()
{
return array(
'admin_pool' => $this->container->get('sonata.admin.pool'),
);
}
}
Now standard layout is free for any 3rd party inheritance.
Nice solution! If you need to extend the sonata layout you will have to at least at the admin_pool variable and pass it to your template:
$admin_pool = $this->get('sonata.admin.pool');
return $this->render('ProjectBundle:Controller:page.html.twig', array(
'admin_pool' => $admin_pool
));
Also see:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With