Build Status Scrutinizer Quality Score Latest Stable Version Total Downloads

SensioLabsInsight knpbundles.com

Overview

Base Sonata Admin only allow you to add CRUD entry in it’s main navigation.

PrestaSonataNavigationBundle allow you to add custom action (for example PrestaCMS page administation) in SonataAdmin main navigation menu.

This bundle allow you to finely tune user right on each menu entry and add the possibility to have an extra description for each sub menu.

Installation

Get the code

The easiest way is to use composer :

php composer.phar require presta/sonata-navigation-bundle --no-update
php composer.phar update presta/sonata-navigation-bundle

Update your Kernel

<?php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            ...
            new Presta\SonataNavigationBundle\PrestaSonataNavigationBundle()
        );
    }
}

Add it to you layout

If not already done, extends your sonata admin layout.

The best way to do that is to easy-extends SonataAdminBundle like this :

php app/console sonata:easy-extends:generate SonataAdminBundle --dest=src

Then create a new template: Application\Sonata\AdminBundle\Resources\views\layout.html.twig

This template code should look like this :

{% extends 'SonataAdminBundle::standard_layout.html.twig' %}

{% block sonata_top_bar_nav %}
    {{ knp_menu_render('presta_sonata_navigation.menu.main', {'allow_safe_labels' : true}, 'list') }}
{% endblock %}

Now you just need to configure Sonata Admin to point to your new layout like this :

sonata_admin:
    templates:
        layout:  ApplicationSonataAdminBundle::layout.html.twig

Try PrestaSonataAdminExtendedBundle

Navigation is just one of our utils for SonataAdmin, maybe you should try our Admin extended bundle.

Add new menu entry

Configuration

Now you just need to add some configuration to add new entry in your navigation. Here is an example taken from PrestaSonataAdminExtendedBundle

presta_sonata_navigation:
    menu:
        items:
            user:
                route: admin_sonata_user_user_list
                roles:
                    - ROLE_ADMIN_USER
                children:
                    users:
                        route: admin_sonata_user_user_list
                    groups:
                        route: admin_sonata_user_group_list

Pay attention to the “roles” entry which allow you to define user role to access this menu.

Translations

By default, navigation translation are made with PrestaSonataNavigationBundle translation domain so you will need to add a PrestaSonataNavigationBundle.en.xliff file (or yml if you want) to add you new menu entries.

You want to disable description you just need to add ‘with_description: false’ configuration under presta_sonata_navigation.

presta_sonata_navigation:
    menu:
        with_description: false
        items:
            ...

How to get help and support

If you need help on one of our bundle, please register to our google group and ask you question. You can open issues on github too.


Want do contribute ? Just fork and edit it!