I am trying to add a mass action item to the product grid mass action block using an observer.
Here is what I am doing but it does not seem to be working, I feel like I am missing something
app/code/DigitalPianism/ProductExport/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="DigitalPianism_ProductExport" setup_version="0.0.1" />
</config>
app/code/DigitalPianism/ProductExport/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'DigitalPianism_ProductExport',
__DIR__
);
app/code/DigitalPianism/ProductExport/etc/adminhtml/events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="adminhtml_catalog_product_grid_prepare_massaction">
<observer name="digitalpianism_productexport_add" instance="DigitalPianism\ProductExport\Observer\AddMassExportAction" />
</event>
</config>
app/code/DigitalPianism/ProductExport/Observer/AddMassExportAction.php
<?php
namespace DigitalPianism\ProductExport\Observer;
use Magento\Framework\Event\ObserverInterface;
class AddMassExportAction extends ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
$block = $observer->getEvent()->getBlock();
$block->getMassactionBlock()->addItem(
'productexport',
[
'label' => __('Export to CSV'),
'url' => $block->getUrl('productExport/productexport/exportCsv')
]
);
}
}
Thanks.