How to Check if a Module is Enabled or Not Programmatically in Magento 2
Many times, developers would come across a requirement to check if a module is enabled or disabled in a Magento 2 store.
It happens when one needs to check about the module’s status is a multi-store or when you are using third-party modules.
Use the isEnabled() function as shown below to check if a module is enabled or not programmatically in Magento 2.
Method to check if a module is enabled or not programmatically in Magento 2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<?php namespace [Vendor]\[Module]\Helper; use Magento\Framework\App\Helper\AbstractHelper; use Magento\Framework\App\Helper\Context; use Magento\Framework\Module\Manager; class Data extends AbstractHelper { protected $moduleManager; public function __construct( Context $context, Manager $moduleManager ) { $this->moduleManager = $moduleManager; parent::__construct($context); } public function isEnable() { if ($this->moduleManager->isEnabled('[Vendor]_[Module]')) { //code for Module is enabled return 1; } else { //code for Module is disabled return 0; } } } |
Note: The above method checks only if the module is enabled in the configuration or not. It does not support checking the status for the admin panel.
That’s it.
Any doubts? If so, do mention them in the Comments section below. I’d be happy to help.
Also, please share the solution with the Magento community via social media.
Thank you.
Chandresh Chauhan
He has been with Meetanshi for more than three years now as a certified Magento developer. A silent guy whom you can always find solving clients' issues, is an avid reader too.
Prev
How to Change The Product Gallery View to The List View in Magento 2
Best Practices for E-commerce Thank You Page
Next