I need to add mass action based on Settings.

If in Configuration settings, it is set to "Yes/Enable" than only that particular mass-action should be added to product grid.

I know I can directly add mass-action using ui_component product_listing.xml. ? But case is how to check Configuration settings and add or remove based on that?

  • Also if not possible with ui_component - product_listing.xml, than the other way I think is to do it with event observer. but again I am not able to do it with either way with event observer also. Commented Dec 2, 2016 at 14:02
  • I tried to do it using a plugin, but unsuccessfully. I don't know how to disable the action element inside the child components of the mass-action. If my research is interesting for you I can post it as an answer later. Commented Dec 2, 2016 at 14:19
  • For event observer, please check this question magento.stackexchange.com/questions/148638/… Commented Dec 2, 2016 at 14:28
  • @SiarheyUchukhlebau Means you want to remove an item from mass-action drop-down.? Commented Dec 2, 2016 at 14:31
  • Yes, I tried to make it, but without success :( Commented Dec 3, 2016 at 10:41

2 Answers 2


To add a custom mass action to ui grid based on some condition you can use custom class for massaction ui component:

<?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="YourNamespace\YourModule\Ui\CustomMassAction"/>

And implement this class extending the core component from Magento_Ui module.

namespace YourNamespace\YourModule\Ui;
use Magento\Ui\Component\MassAction;
class CustomMassAction extends MassAction
    public function prepare()

        if ($this->isEnabled()) {
            $config = $this->getConfiguration();
            $config['actions'][] = [
                'component' => 'uiComponent',
                'type' => 'custom',
                'label' => 'Custom',
                'url' => '//google.com'
            $this->setData('config', $config);

    public function isEnabled()
        return true; // access your configuration here

Alternatively you can apply vice-versa approach :) . Specify configuration for your massaction in product_listing.xml and remove your action from configuration in custom massaction class if it is disabled in your configuration.

Another way to customize mass actions is adding a plugin for Magento\Ui\Component\MassAction::prepare.


You can add mass actions to Magento 2 admin grid using the following XML in the grid XML file:

<listingToolbar name="listing_top">
    <bookmark name="bookmarks"/>
    <columnsControls name="columns_controls"/>
    <filters name="listing_filters"/>
    <paging name="listing_paging"/>
    <massaction name="listing_massaction">
        <action name="update_status">
                <label translate="true">Update status</label>
                <actions class="{Namespace}\{Module}\Ui\Component\MassAction\Status\Options"/>
        <action name="delete">
                    <message translate="true">Are you sure to delete selected items?</message>
                    <title translate="true">Delete items</title>
                <url path="{frontname}/{controller}/{action}"/>
                <label translate="true">Delete</label>

You then need to create your own controller and actions class if necessary. How to add mass action to Magento 2 admin grid? explains in detail how to add mass actions to your Magento 2 admin grid.

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.