I have created a custom reports using ui components.

For the export csv I have created a plugin class for this function.


<type name="Magento\Ui\Model\Export\MetadataProvider">
        <plugin name="custom_export1" type="Vendor\Report1\Plugin\ModifyExportPlugin" sortOrder="1" disabled="false"/>

I have used the same plugin in another 4 modules.


<type name="Magento\Ui\Model\Export\MetadataProvider">
        <plugin name="custom_export2" type="Vendor\Report2\Plugin\ModifyExportPlugin" sortOrder="1" disabled="false"/>

From the above code, if i export from any of the module, both the plugins are called, I need to avoid that,

When export is happened from Module Report1,the plugin from that module to be executed, if called from Report2, the plugin defined in that module need to call.

How this can be achieved? Can anyone help me to resolve this issue. Thanks in advance!!

  • 1
    what methods from the MetadataProvider class are you pluginizing? Or better yet, maybe you should also include the code of one of your plugins and explain what it does. – Marius Jul 27 at 15:25
  • Check this post if it's helpful! magento.stackexchange.com/questions/256613/… – Bhaumik Upadhyay Jul 27 at 19:39
  • Are you create before, after or arround plugin? – Dhiren Vasoya Jul 30 at 14:11
  • @DhirenVasoya, I used After Plugin – Manjunath Jul 30 at 14:49
  • @BhaumikUpadhyay, the above solution is not clear.can you elaborate it please, how that can be used in my scenario – Manjunath Jul 30 at 14:50

I'm not sure if I understood your problem, but you may check the modulename of the request in your plugin methods and execute the code only if the request module name matches.

For example adding some code like this in your plugins may help you solving the problem (example for module Report1):

namespace Vendor\Report1\Plugin;
class ModifyExportPlugin
    protected $request;
    public function __construct(
       \Magento\Framework\App\RequestInterface $request
    ) {
       $this->request = $request;
    //check the current request module name in your plugin functions
    if (request->getModuleName() == 'report1'){
        //place your plugin code here...

In addition to have module specific controllers (for gridToCsv and gridToXml) you should create for each module a controller extending the original controller of the Ui module. Example for GridToCsv for module Report1 (place this content into GridToCsv.php in Controller/Adminhtml/Export directory):

namespace Vendor\Report1\Controller\Adminhtml\Export;

class GridToCsv extends \Magento\Ui\Controller\Adminhtml\Export\GridToCsv

Create a routes.xml file in etc/adminthtml of your module (if it not exists already). Example for module Report1:

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="admin">
        <route frontName="report1" id="report1">
            <module name="Vendor_Report1" before="Magento_Backend" />

The definition of the ui component should be updated for each module like in this answer How to override definition.xml file in Magento 2? Especially the urlparameter should be like this according to the code above (Example for module Report1 and action gridToCsv):

<item name="url" xsi:type="string">report1/export/gridToCsv</item>

If you make these changes for all the affected modules, the approach should work.

| improve this answer | |
  • hi @Helge, Yes I tried this, I am getting ModuleName as Mui, so this is not helpful. – Manjunath Jul 24 at 7:56
  • OK, so your ui definition is not modified and all of your modules are using mui/export/gridToCsvor mui/export/gridToXml. One option could be to change the controllers in the ui definition to have a specific controller for each module (e.g. report1/export/gridToCsv) and than you can use the suggested approach. The new controller do not need any logic just extend the original. See this answer how you can do that. magento.stackexchange.com/questions/268277/… – HelgeB Jul 24 at 8:06
  • hi @Helge, so <item name="url" xsi:type="string">{your_frontname}/export/gridToCustomCsv</item> this line for creating custom controller, what code should i write in each of the controller, The answer is Incomplete there – Manjunath Jul 24 at 8:10
  • can you please update here in your answer? – Manjunath Jul 24 at 8:15
  • @Manjunath I have updated the answer, I hope that helps you to get the stuff running :-) – HelgeB Jul 24 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.