How to disable or hide the core module ACL resources in magento 2 with the custom module. I have tried the following syntax and it does not work:
<resource id="Magento_Backend::content" remove="true">
How to disable or hide the core module ACL resources in magento 2 with the custom module. I have tried the following syntax and it does not work:
<resource id="Magento_Backend::content" remove="true">
You can create a custom module for that and use a before
plugin for \Magento\Integration\Helper\Data::mapResources()
.
Let's name the module StackExchange_Acl
.
You will need these files:
app/code/StackExchange/Acl/registration.php
- the registration file
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'StackExchange_Acl',
__DIR__
);
app/code/StackExchange/Acl/etc/module.xml
- module file
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="StackExchange_Acl" setup_version="1.0.0" />
</config>
app/code/StackExchange/acl/etc/di.xml
- di admin file to declare your plugin
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Integration\Helper\Data">
<plugin name="acl-intergration-data" type="StackExchange\Acl\Plugin\Integration\Data" sortOrder="100" />
</type>
</config>
app/code/StackExchange/Acl/Plugin/Integration/Data.php
- the plugin
<?php
namespace StackExchange\Acl\Plugin\Integration;
class Data
{
public function beforeMapResources(\Magento\Integration\Helper\Data $helper, array $resources)
{
$restricted = $this->getRestrictedIds();
foreach ($resources as $key => $resource) {
if (in_array($resource['id'], $restricted)) {
unset($resources[$key]);
}
}
return [$resources];
}
//list in this method all the ids of the acl's you don't want to show
//if you don't want to had-code them you can read them from a config file - but you have to build that yourself.
protected function getRestrictedIds()
{
return ['Magento_Sales::sales', 'Magento_Backend::dashboard'];
}
}
run php bin/magento setup:upgrade
and you are done.
\Magento\User\Block\Role\Tab\Edit::getTree
Feb 16, 2016 at 15:01
u can set value 0 in app/etc/config.php