23

How to get the modules list in Drupal as in admin/build/modules?

Davide Casiraghi
  • 15,591
  • 9
  • 34
  • 56
sultan
  • 5,978
  • 14
  • 59
  • 103

6 Answers6

51

You can use drush pm-list --type=Module --status=enabled command for getting a list of installed modules.

Gokul N K
  • 2,428
  • 2
  • 32
  • 40
9

Install "Drush" (a good option in any case, once you get used to it, you'll love it). It has a build in command to list all installed modules themes.

If you need to see the list of modules to display it elsewhere (this can be a security issue!), you can look into the way how drush does it (pm.drush.inc:218).

Furthermore there is a core function, but I don't know if this is what you want.

Balu Ertl
  • 313
  • 5
  • 6
DrColossos
  • 12,656
  • 3
  • 46
  • 67
  • I need to display the list of modules and themes in a web interface to make possible user to select themes and modules – sultan Nov 20 '10 at 11:03
  • Then why can't you use the build/modules view for it? Or are you talking about simply displaying it without any other functions? – DrColossos Nov 20 '10 at 11:10
  • I am new to build/modules how to use it? ) – sultan Nov 20 '10 at 11:25
  • It's your path given from above (I just omitted the `admin` part for lazyness ;)) – DrColossos Nov 20 '10 at 11:27
  • So you mean there is no inner functions supported and I should to code this on my own? – sultan Nov 20 '10 at 11:29
  • 1
    What are you even trying to do? Log into the admin and enable/disable modules and themes. There is no need for programming it. – Kevin Nov 20 '10 at 18:18
  • I've developing scaling toolkit pack for a drupal sites so the admin user can easily scale and create new sub-sites and sub-domains of drupal sites thats why I need to provide theme/module selection... – sultan Nov 21 '10 at 08:00
  • Solution already found. Achieve this using system_modules function as an argument to a drupal_get_form function – sultan Nov 22 '10 at 13:37
  • This defined at modules/system.module:313-320 – sultan Nov 22 '10 at 13:39
1
module_list($refresh = FALSE, $bootstrap_refresh = FALSE, $sort = FALSE, $fixed_list = NULL)

Here are more details. http://api.drupal.org/api/drupal/includes!module.inc/function/module_list/7

Kandinski
  • 953
  • 11
  • 30
1

If you want to list all the modules available to you, this should work with either Drupal 6 or Drupal 7:

<?php
// include_once('.' . base_path() . drupal_get_path('module', 'system') . '/system.admin.inc');
// Above line was intentionally commented out (see below).
$drupal_version = (int) VERSION;
$list_modules_function = '';
if ($drupal_version >= 7 && $drupal_version < 8) {
  $list_modules_function = 'system_rebuild_module_data';
}
else if ($drupal_version >= 6 && $drupal_version < 7) {
  $list_modules_function = 'module_rebuild_cache';
}
if (empty($list_modules_function)) {
  $output = t('Oops... Looks like you are not using either version 6 or version 7 of Drupal');
}
else if (!function_exists($list_modules_function)) {
  $output = t('Oops... Unable to find the function !function(). Try uncommenting the top line of this code.', array('!function' => $list_modules_function));
}
else {
  $output = "<dl>\n";
  $list_modules = $list_modules_function();
  foreach ($list_modules as $module) {
    $output .= "<dt>" . check_plain($module->info["name"]) . "</dt>\n";
    $output .= "<dd>" . check_plain($module->info["description"]) . "</dd>\n";
  }
  $output .= "</dl>\n";
}
print $output;
?>
jerdiggity
  • 3,655
  • 1
  • 29
  • 41
  • can you explain what is t() here? I am getting Fatal error: Call to undefined function t() error – sheetal Apr 29 '17 at 05:39
  • t() is a function used for several purposes, but its primary purpose is to translate text. See this [API documentation](https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/t/7.x) for more information. – jerdiggity Apr 30 '17 at 06:32
1

You can also use following commands to search specific modules. If you want to list-down only commerce module from module list than

drush pml | grep commerce

On windows machine you cant use grep. So you have to use findstr

drush pml | findstr commerce
Firoz Sabaliya
  • 643
  • 5
  • 19
1

The following command will work, outputing list of all available modules along with the package they fall in, status and version.

drush pm-list --type=Module --status=enabled
Mariusz Jamro
  • 30,615
  • 24
  • 120
  • 162
Dev
  • 212
  • 1
  • 14
  • 1
    Not nice to copy the answer from one of the comments ;) – Peanut May 01 '15 at 07:23
  • Just used it, and it worked for me. I don't have enough reputations to +1 any comment or question, so I think writing what worked for me will support the solution... :p :D – Dev May 01 '15 at 11:06