1

By using this link i am able to get all extensions list in Magento 2. But i want to get only Third Party extensions which are installed in app/code directory.

For example, there are 3 modules in app/code directory, then i only want to get list of these 3 modules.

  • there is no such way available at Magento 2 – Amit Bera Feb 13 at 9:20
  • @AmitBera i just want to get list of modules available in app/code directory. yash7690 provided a solution to fulfill my requirement. And thank you for your help. – iqbal malik Feb 13 at 9:53
1

You may create some Model file in your module as follow.

File: Model/CodeModules.php

<?php
namespace [Vendor]\[Module]\Model;

class CodeModules
{
    protected $moduleList;
    protected $moduleReader;

    public function __construct(
        \Magento\Framework\Module\ModuleList $moduleList,
        \Magento\Framework\Module\Dir\Reader $moduleReader
    ) {
        $this->moduleList = $moduleList;
        $this->moduleReader = $moduleReader;
    }

    public function getCustomModules()
    {
        $result = [];

        $modules = $this->moduleList->getNames();
        foreach ($modules as $_module) {
            $dir = $this->moduleReader->getModuleDir(null, $_module);
            if(strpos($dir, 'app/code') !== false)
            {
                $result[] = $_module;
            }
        }

        return $result;
    }
}

Now call this function getCustomModules() wherever needed and you will get your expected result.

  • 2
    a module does exits at app/code folder not means it is 3rd party.Suppose, you have clone Magento 2 from GitHub repo then Magento own module exits at app/code/ folder. That is means Magento own module are 3 party module – Amit Bera Feb 13 at 9:22
  • Some time composer also add third party module in vendor folder – Zaheerabbas Feb 13 at 14:10

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.