Skip to main content
added 815 characters in body
Source Link
Rohan Hapani
  • 17.5k
  • 9
  • 55
  • 96

Try to use thisYou can get by using below code2 ways :


EDIT 1 :

protected $fullModuleList;
protected $moduleManager;

public function __construct(
    ...................
    \Magento\Framework\Module\FullModuleList $fullModuleList,
    \Magento\Framework\Module\Manager $moduleManager,
    ...................
) {

    $this->fullModuleList = $fullModuleList;
    $this->moduleManager = $moduleManager;
}

public function yourFunction()
{
    ...
    $allModules = $this->fullModuleList->getAll();
    $listOfModules = [];
    foreach ($allModules as $key => $value) {
        $listOfModules[] = $key;
    }
    foreach ($listOfModules as $key => $value) {
        if ($this->moduleManager->isEnabled($value)) {
            echo $value; //Enable Module List
        } else {
            echo $value; //Disable Module List
        }
    }
    ...
}

EDIT 2 :

protected $fullModuleList;
protected $moduleList;

public function __construct(
    ...................
    \Magento\Framework\Module\FullModuleList $fullModuleList,
    \Magento\Framework\Module\ModuleList $moduleList,
    ...................
) {

    $this->fullModuleList = $fullModuleList;
    $this->moduleList = $moduleList;
}

public function yourFunction()
{
    ...
    $allModules = $this->fullModuleList->getNames(); //List of All Module Names
    $enabled_list = $this->moduleList->getNames(); //List of Enabled Module Names
    $disabled_list = array_diff($enabled_list, $allModules); //List of Disabled Module Names
    ...
}

Try to use this below code :

protected $fullModuleList;
protected $moduleManager;

public function __construct(
    ...................
    \Magento\Framework\Module\FullModuleList $fullModuleList,
    \Magento\Framework\Module\Manager $moduleManager,
    ...................
) {

    $this->fullModuleList = $fullModuleList;
    $this->moduleManager = $moduleManager;
}

public function yourFunction()
{
    ...
    $allModules = $this->fullModuleList->getAll();
    $listOfModules = [];
    foreach ($allModules as $key => $value) {
        $listOfModules[] = $key;
    }
    foreach ($listOfModules as $key => $value) {
        if ($this->moduleManager->isEnabled($value)) {
            echo $value; //Enable Module List
        } else {
            echo $value; //Disable Module List
        }
    }
    ...
}

You can get by using below 2 ways :


EDIT 1 :

protected $fullModuleList;
protected $moduleManager;

public function __construct(
    ...................
    \Magento\Framework\Module\FullModuleList $fullModuleList,
    \Magento\Framework\Module\Manager $moduleManager,
    ...................
) {

    $this->fullModuleList = $fullModuleList;
    $this->moduleManager = $moduleManager;
}

public function yourFunction()
{
    ...
    $allModules = $this->fullModuleList->getAll();
    $listOfModules = [];
    foreach ($allModules as $key => $value) {
        $listOfModules[] = $key;
    }
    foreach ($listOfModules as $key => $value) {
        if ($this->moduleManager->isEnabled($value)) {
            echo $value; //Enable Module List
        } else {
            echo $value; //Disable Module List
        }
    }
    ...
}

EDIT 2 :

protected $fullModuleList;
protected $moduleList;

public function __construct(
    ...................
    \Magento\Framework\Module\FullModuleList $fullModuleList,
    \Magento\Framework\Module\ModuleList $moduleList,
    ...................
) {

    $this->fullModuleList = $fullModuleList;
    $this->moduleList = $moduleList;
}

public function yourFunction()
{
    ...
    $allModules = $this->fullModuleList->getNames(); //List of All Module Names
    $enabled_list = $this->moduleList->getNames(); //List of Enabled Module Names
    $disabled_list = array_diff($enabled_list, $allModules); //List of Disabled Module Names
    ...
}
Source Link
Rohan Hapani
  • 17.5k
  • 9
  • 55
  • 96

Try to use this below code :

protected $fullModuleList;
protected $moduleManager;

public function __construct(
    ...................
    \Magento\Framework\Module\FullModuleList $fullModuleList,
    \Magento\Framework\Module\Manager $moduleManager,
    ...................
) {

    $this->fullModuleList = $fullModuleList;
    $this->moduleManager = $moduleManager;
}

public function yourFunction()
{
    ...
    $allModules = $this->fullModuleList->getAll();
    $listOfModules = [];
    foreach ($allModules as $key => $value) {
        $listOfModules[] = $key;
    }
    foreach ($listOfModules as $key => $value) {
        if ($this->moduleManager->isEnabled($value)) {
            echo $value; //Enable Module List
        } else {
            echo $value; //Disable Module List
        }
    }
    ...
}