How to state ACL for the Configuration Page of Custom Module in Magento 2

Here the following steps help you how to state ACL for the Configuration Page of Custom Module in Magento 2:

Step 1: State the source of the configuration page in System.xml

Step 2: State ACL for the config page

In the previous article, we showed you how to write ACL for the custom package menu: how to create an admin ACL in Magento 2. Now you can learn how to declare your ACL to your custom module.

State the source of the configuration page in System.xml

File: /app/code/[NameSpace]/[ModuleName]/etc/adminhtml/system.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">

    <system>

        <tab id="Webnexs" translate="label" sortOrder="100">

            <label>Webnexs</label>

        </tab>

        <section id="[modulename]" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">

            <class>separator-top</class>

            <label>Custom Module Configuration</label>

            <tab>Webnexs</tab>

            <resource>[NameSpace]_[ModuleName]::configuration</resource>

            <group id="general" translate="label" sortOrder="1" type="text" showInDefault="1" showInWebsite="0">

                <label>Custom Module Configuration</label>

                ...

            </group>

        </section>

    </system>

</config>

You can observe that I include the resource into configuration section of my Custom Module:

<resource>[NameSpace]_[ModuleName]::configuration</resource>

I use this source ID to note down a new ACL in next step.

File: / app / code / [NameSpace]/[ModuleName] /etc/acl.xml

In this step, I will write a new ACL for the [NameSpace] _ [ModuleName] :: structure I’ve announced in step 1.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">

    <acl>

        <resources>

            <resource id="Magento_Backend::admin">

                ...

                <resource id="Magento_Backend::stores">

                    <resource id="Magento_Backend::stores_settings">

                        <resource id="Magento_Config::config">

                            <resource id="[NameSpace]]_[ModuleName]::configuration" title="Custom Module Settings" translate="title" />

                        </resource>

                    </resource>

                </resource>                 

            </resource>    

        </resources>     

    </acl>

</config>

The 2 steps I mentioned above are a short process to announce the ACL to the custom block configuration page in Magento 2. With this guide, you can easily manage Magento Module 2 module module. Each store has a config page with Magento 2 custom module with many attributes.

Last Update: April 7, 2018  

March 7, 2018   556   Nandini Ramachandran    Operations    
Total 2 Votes:
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
Twitter
INSTAGRAM
LinkedIn