2

I am working on creating a base module for all other modules under one namespace.

I want to show a list of all modules (with their version and their status as enabled or disabled).

I have injected dependency of \Magento\Framework\Module\ModuleListInterface in my block file, but I am not getting the module in the list if I disable it.

I have tried getAll() and getNames() functions. No function is returning disabled module names in the list.

Previously it was possible to get the list of all modules because there was a section in admin panel (Advanced), where all modules were listed with respective module output.

Kindly help me to get the list of all modules.

2
  • How to find out which Magento module is customize/extended in Magento 2? Mar 27, 2020 at 8:29
  • I think you need to ask a new question instead of commenting here. Mar 27, 2020 at 9:25

2 Answers 2

6

After some study of Magento core modules, I checked the source, from where the following command is executed:

php bin/magento module:status

I found that Magento is using \Magento\Framework\Module\FullModuleList class to get the list of enabled and disabled modules.

Based on Magento's implementation, I have implemented my code in the following way:

<?php
namespace Mohit\Base\Block;

class Modules extends \Parent\Class
{
    protected $fullModuleList;

    public function __construct(
        \Other\Dependenciy\Classes,
        \Magento\Framework\Module\FullModuleList $fullModuleList
    ) {

        $this->fullModuleList = $fullModuleList;
    }

    public function modulesList()
    {
        ...
        $allModules = $this->fullModuleList->getAll();
        ...
    }
}

Also, tons of thanks to @sanne, who helped me to go in the right direction.

1
  • If we want to get a list of modules which exists in app/code directory, then what should I do ?? Feb 13, 2019 at 8:11
4

A shot in the dark here, but maybe you could look how the terminal function bin/magento module:status works and copy that somehow? Because that shows all modules and the statuses? No idea how though.

1
  • 1
    Thanks, @sanne for the answer. I had been checking the same while you answered. Upvoted for the precious help. Jul 19, 2018 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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