I want to hide "ADD NEW CUSTOMER"
button on customer_grid page for certain admin roles, how to specify Specify ACL's for ui_components..?
Add a comment
|
app/code/SR/MagentoCommunity/view/adminhtml/ui_component/customer_listing.xml
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<settings>
<buttons>
<button name="add" class="SR\MagentoCommunity\Ui\Customer\AddButton"/>
</buttons>
</settings>
</listing>
app/code/SR/MagentoCommunity/Ui/Customer/AddButton.php
Change Magento_Cms::save to your new role
<?php
namespace SR\MagentoCommunity\Ui\Customer;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
use Magento\Framework\AuthorizationInterface;
class AddButton implements ButtonProviderInterface
{
/**
* Url Builder
*
* @var \Magento\Framework\UrlInterface
*/
protected $urlBuilder;
/**
* @var AuthorizationInterface
*/
private $authorization;
/**
* AddButton constructor.
*
* @param \Magento\Backend\Block\Widget\Context $context
* @param AuthorizationInterface $authorization
*/
public function __construct(
\Magento\Backend\Block\Widget\Context $context,
AuthorizationInterface $authorization
) {
$this->urlBuilder = $context->getUrlBuilder();
$this->authorization = $authorization;
}
/**
* @return array
*/
public function getButtonData()
{
if (!$this->authorization->isAllowed('Magento_Cms::save')) {
return [];
}
return [
'label' => __('Add New Customer'),
'on_click' => sprintf("location.href = '%s';", $this->getUrl('*/*/new')),
'class' => 'primary',
'sort_order' => 10
];
}
/**
* Generate url by route and parameters
*
* @param string $route
* @param array $params
* @return string
*/
public function getUrl($route = '', $params = [])
{
return $this->urlBuilder->getUrl($route, $params);
}
}
-
-
You change this Magento_Cms::save to your role id, that I already said. I tested using that in my local. – Sohel Rana Feb 18 '19 at 14:12
-
I don't know what is your role, so create new one acl.xml, and change here – Sohel Rana Feb 18 '19 at 14:13
-
okay, are you able to hide that button for different role other than admin..? – Magento Dev Feb 18 '19 at 14:19
-