19

In Magento 2, is it possible to check if a module's installed at runtime?

In Magento 1 I'd either use the isModuleEnabled helper method, or manually fetch the global configuration tree and check the nodes under <modules/>.

Is there an isModuleEnabled equivalent in Magento 2? If not how can I grab the global configuration and check for the module nodes I want?

2 Answers 2

16

Maybe you are looking for this?

lib/internal/Magento/Framework/Module/Manager.php

/**
 * Whether a module is enabled in the configuration or not
 *
 * @param string $moduleName Fully-qualified module name
 * @return boolean
 */
public function isEnabled($moduleName)
{
    return $this->_moduleList->has($moduleName);
}

Also there is method isOutputEnabled in the same class. depricated since v. 2.2.0

Example of usage:

if (!$this->_moduleManager->isEnabled('Magento_Reports')) {
1
  • Yup, that's what I was looking for! Commented Aug 10, 2015 at 17:14
3

Part of goal of using composer is you can ensure dependencies exist, or else module won't install. However there is this "disable" output mode that is a little weird, but is more like "quick, it's broken, turn it off until we can fix it properly".

So the concept of is module enabled is not quite the same in m2.

Having said that, I am pretty sure there is such an API, but it might not yet be marked as public/supported with @ API annotation

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.