回答:
これは、MassActionsの新しいクラスを作成することで実行できます。
<?php
namespace YourVendor\YourModule\Ui;
class MassAction extends \Magento\Ui\Component\MassAction
{
private $authorization;
public function __construct(
\Magento\Framework\View\Element\UiComponent\ContextInterface $context,
\Magento\Framework\AuthorizationInterface $authorization,
$components,
array $data
) {
$this->authorization = $authorization;
parent::__construct($context, $components, $data);
}
public function prepare()
{
parent::prepare();
$config = $this->getConfiguration();
if (!$this->authorization->isAllowed('YourVendor_YourModule::the_acl_youd_like_to_use')) {
$allowedActions = [];
foreach ($config['actions'] as $action) {
if ('delete' != $action['type']) {
$allowedActions[] = $action;
}
}
$config['actions'] = $allowedActions;
}
$this->setData('config', (array)$config);
}
}
app/code/YourVendor/YourModule/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">
<listingToolbar name="listing_top">
<massaction name="listing_massaction" class="YourVendor\YourModule\Ui\MassAction"/>
</listingToolbar>
</listing>
プラグインを使用して行うことができます(ベストアプローチ):
app / code / Devcrew / DeleteRestriction / etc / adminhtml / di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Ui\Component\Product\MassAction">
<plugin name="hide_delete_from_catalog_massaction" type="Devcrew\DeleteRestriction\Plugin\Catalog\Ui\Component\Product\MassAction" sortOrder="1"/>
</type>
</config>
app / code / Devcrew / DeleteRestriction / Plugin / Catalog / Ui / Component / Product / MassAction.php
<?php
namespace Devcrew\DeleteRestriction\Plugin\Catalog\Ui\Component\Product;
class MassAction
{
public function __construct( \Magento\Backend\Model\Auth\Session $adminSession)
{
$this->_adminSession = $adminSession;
}
public function afterIsActionAllowed(
\Magento\Catalog\Ui\Component\Product\MassAction $subject,
$isAllowed,
$actionType
) {
$roleData = $this->_adminSession->getUser()->getRole()->getData();
//Remove Delete Button for Admin users except Administrators
if ($actionType == 'delete' && trim($roleData['role_name'])!=='Administrators') {
return false;
}
return $isAllowed;
}
}