How to give ‘custom menu’ permissions to a role?

Some weeks ago I created a new custom menu in backend. Now I want to select this new menu in order to give permissions (or not) to the roles that I have on my website. The problem is that this new custom menu doesn't appears in the resources of the role. You can see this menu only if you have all the access granted.

 

—————————————————-

Here is the solution:

 

You need to create in your extension, inside the etc folder a file named adminhtml.xml. In this file you should have the ACL for your menu. Actually you should have the menu in here also but it works even if you added the menu in config.xml
In this file you need to add an xml structura similar to the one you added for the menu.
Here is an example. Let's assume you have a video module and the menu looks like this:

<menu>
    <video translate="title" module="video"><!-- this is the top  level menu -->
        <title>Video</title>
        <sort_order>65</sort_order>
        <children>
            <video translate="title" module="video"><!-- this is the submenu item -->
                <title>Videos</title>
                <action>adminhtml/video</action>
                <sort_order>100</sort_order>
            </video>
        </children>
    </video>
</menu>

For this menu structure you need the following adminhtml.xml file

<?xml version="1.0"?>
<config>
    <acl>
        <resources>
            <admin>
                <children>
                    <video translate="title" module="video"><!-- this is the top  level menu -->
                        <title>Video</title>
                        <children>
                            <video translate="title" module="video"><!-- this is the submenu item -->
                                <title>Videos</title>
                            </video>
                        </children>
                    </video>
                </children>
            </admin>
        </resources>
    </acl>
</config>

Clear the cache and you should be able to see your menu in the user roles permissions section.

Revisions

No comments yet.

Leave a Reply