-2

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).

  • Dont know why ... maybe add some code from your acl.xml? However .... +1 – sv3n Apr 19 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. – Mohit Kumar Arora May 20 at 9:19
8

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

  • Okay, thanks @melaxon. I will check and will get back to you soon. – Mohit Kumar Arora Apr 18 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. – Mohit Kumar Arora Apr 19 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 Apr 19 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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