Skip over navigation
Documentation
You are currently viewing documentation for version 3.0 which is not a long-term support release. The latest long-term support release is version 2.6

How to Create and Customize the Application Menu

Used application: OroCRM 1.7

In OroPlatform you can create your fully personalized menu or use a simple technique to add or override a section in the default menu. This tutorial describes how to override a section in the default menu.

Let’s assume that you already have a bundle with the namespace Acme\Bundle\NewBundle in the /src directory with annotation configuration format generated or created manually.

Create your route with annotation

First, you have to go to your default controller, create your action and specify the @Route and @Template annotations:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
// src/Acme/Bundle/NewBundle/Controller/DefaultController.php
namespace Acme\Bundle\NewBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class DefaultController extends Controller
{
    /**
     * @Route("/hello", name="acme_link")
     * @Template()
     */
    public function indexAction()
    {
        return array('name' => "John Doe");
    }
}

See also

You can read more about both the @Route and the @Template annotation in the SensioFrameworkExtraBundle documentation.

Next, you should create a template for your action with the following content:

1
2
3
4
5
{# src/Acme/Bundle/NewBundle/Resources/views/Default/index.html.twig #}
{% extends "OroUIBundle:Default:index.html.twig" %}
{% block content %}
     <h1>Hello, {{ name }}!</h1>
{% endblock content %}

And finally, you should register your bundle routes. To do that you have to create a routing.yml file with the following content:

1
2
3
4
5
# src/Acme/Bundle/NewBundle/Resources/config/oro/routing.yml
acme_new_bundle:
    resource:     "@AcmeNewBundle/Controller"
    type:         annotation
    prefix:       /acme

Create navigation configuration

Now we need to create a navigation.yml file with the following content:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# src/Acme/Bundle/NewBundle/Resources/config/oro/navigation.yml
navigation:
    menu_config:
        items:
            acme_tab:
                label: Acme label
                uri:   '#'
                extras:
                    position: 300
            acme_tab_link:
                label: Acme link label
                route: acme_link
        tree:
            application_menu:
                children:
                    acme_tab:
                        children:
                            acme_tab_link: ~

    titles:
        acme_link: My link page title

Then you have to clear cache:

user@host:/var/www/vhosts/platform-application$ php bin/console cache:clear
Clearing the cache for the dev environment with debug true

Note

You can use php bin/console cache:clear command with parameters --env=prod or --env=dev.

Here you can see your new menu items in the default OroPlatform menu:

../../../_images/add_item_to_default_nav.png

And here is the page you’ll see after a click on the menu item:

../../../_images/add_item_page_result_click.png

Override existing section

To override some section in the main menu you have to create the navigation.yml file with the following content (it will add an “Acme link label” link to the sales section):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# src/Acme/Bundle/NewBundle/Resources/config/oro/navigation.yml
navigation:
    menu_config:
        items:
            acme_tab_link:
                label: Acme link label
                route: acme_link
        tree:
            application_menu:
                children:
                    sales_tab:
                        merge_strategy: append
                        children:
                            acme_tab_link: ~

    titles:
        acme_link: My link page title

And clear cache:

user@host:/var/www/vhosts/platform-application$ php bin/console cache:clear
Clearing the cache for the dev environment with debug true

Here you can see the new menu item “Acme link label” in the Sales section:

../../../_images/ov_item_in_default_nav.png
Browse maintained versions:3.01.122.02.32.6

You will be redirected to [title]. Would you like to continue?

Yes No
sso for www.magecore.comsso for oroinc.desso for oroinc.fr
Back to top