3

I want to perform some action when my custom module gets disable. Is there any observer event or plugin event that being fired when i disable my module?

Any help would be appreciated.

Thank you,

  • in my opinion you can't use observers or plugins because magento core doesn't load. The "setup" part works with own logic without support of interceptors. – sergei.sss Feb 28 at 11:33
  • I think we can use plugin because controller's execute method is public. So i think we can implement with controller but not sure how to implement when we disable mymodule. – Jackson Wyss Feb 28 at 11:51
  • What controller do you mean? Your extension may be disabled from CLI. You can try add plugin to Magento\Setup\Console\Command\ModuleDisableCommand::run() but it useless... – sergei.sss Feb 28 at 12:00
0

For that purpose you can create the Recurring script and use Magento\Framework\Module\Manager to check your module.

All recurring scripts executing are during each launch of the setup:upgrade command. Or you can use any other event to make changes.

Code will be something like this:

// Initialize module manager
public function __construct(
    ...
    \Magento\Framework\Module\Manager $moduleManager,
    ....
) {
    ...
    $this->moduleManager = $moduleManager;
    ...
}

And then check if modules enabled:

if ($this->moduleManager->isEnabled('Vendor_Module')) {
    //the module is enabled
} else {
    //the module is disabled
}
  • where do i put that code? i know how to check module is enable or not. I need even. when you disable or enable from command line it fire specific action. – Jackson Wyss Mar 5 at 17:38

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.