Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrate 3rd party bundles into SonataAdminBundle

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?

like image 725
xdrew Avatar asked Jan 07 '14 20:01

xdrew


2 Answers

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.

like image 195
xdrew Avatar answered Nov 15 '22 04:11

xdrew


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:

  1. Sonata Admin - No Header
  2. show sonata admin menu in every page if the admin is logged in
like image 34
webDEVILopers Avatar answered Nov 15 '22 05:11

webDEVILopers