-1

I have updated the parent of a menu item which is coming from a third party extension. I have updated the menu item by my custom module's menu.xml file.

For instance, the menu was coming under Marketing >> Promotions >> Gift Card History. I have changed the menu position to Reports >> Others >> Gift Card Accounting by using the following code:

<update id="Magestore_Giftvoucher::gifthistory" title="Gift Cards Accounting" sortOrder="40" parent="Stream_ChangeCoreMenuPosition::others"/>

Since the parent of the menu item has been changed, now I need to modify the ACL of this item also.

For this, I don't want to make changes in the extension's acl.xml file. So I have created my own acl.xml in my custom module, but when I add the ACL entry for the modified menu position, I get the following error:

ACL Error

Please help me, how can I modify the ACL of the extension using my custom module (without modifying the extension's files).

2
  • Dont know why ... maybe add some code from your acl.xml? However .... +1
    – sv3n
    Commented Apr 19, 2019 at 13:52
  • 1
    Can someone tell me who are the people who are downvoting on this question and why? Till now there are 8 downvotes without any reason. Commented May 20, 2019 at 9:19

1 Answer 1

10

you need to create a plugin to disable the existing ACL record first

In di.xml

<!-- remove existing record from ACL -->    
<type name="Magento\Integration\Helper\Data">
    <plugin name="my-acl-data" type="VendorName\ModuleName\Plugin\Integration\Data" sortOrder="100" />
</type> 

VendorName\ModuleName\Plugin\Integration\Data.php

namespace VendorName\ModuleName\Plugin\Integration;

class Data
{
    public function beforeMapResources(\Magento\Integration\Helper\Data $helper, array $resources)
    {
        $removed = $this->getIdsToRemove();
        foreach ($resources as $key => $resource) {
            if (in_array($resource['id'], $removed)) {
                unset($resources[$key]);
            }
        }
        return [$resources];
    }
    private function getIdsToRemove()
    {
        return [
            'Magestore_Giftvoucher::gifthistory',
        ];
    }
}

This will remove Magestore_Giftvoucher::gifthistory

Then add your own records in acl.xml : VendorName_ModuleName::yourRecord

4
  • Okay, thanks @melaxon. I will check and will get back to you soon. Commented Apr 18, 2019 at 11:56
  • Great @melaxon, it worked for me. But for that, I had to add the menu item instead of updating the existing one. Also, need to override/pluginize the controller also. Commented Apr 19, 2019 at 13:06
  • e.g. im menu.xml <add id="NewVendor_NewModule::some_id" title="My new item" translate="title" module="NewVendor_NewModule" sortOrder="1" parent="Another_Module::another_item" action="some_action/blah_blah" resource="NewVendor_NewModule::something_manage"/> The best way imho is to search through existing Magento modules for some examples that look like yours and can inspire your
    – melaxon
    Commented Apr 19, 2019 at 20:19
  • how would you override existing third party plugin(LandofCoder) having acl.xml and menu.xml in order to give permission to access that module to other user roles?. Admin is able to access that module but I also want that module to be accessible by other userroles. i have put up my work over here magento.stackexchange.com/questions/326318/…. this concept is really interesting it would be great if someone can guide me through this.
    – J. Doe
    Commented Nov 16, 2020 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.