sultan
sultan

Reputation: 6058

Drupal get module info?

Is there any function in Drupal like get_module_info('MODULE_NAME') or I should parse info file?

Upvotes: 9

Views: 6141

Answers (4)

Vlad Moyseenko
Vlad Moyseenko

Reputation: 223

For Drupal 8.6+:

$info = \Drupal::service("extension.list.module")->getExtensionInfo('mymodule');

Upvotes: 0

Scott Reynen
Scott Reynen

Reputation: 3550

drupal_parse_info_file() is the closest function, but it takes a file path, not a module name, so you have to convert the name into the path first:

$path = drupal_get_path('module', $name) . '/' . $name . '.info';
$info = drupal_parse_info_file($path);

Upvotes: 16

acrollet
acrollet

Reputation: 961

A somewhat easier method (drupal 7 and up) is to use the system_get_info function.

Upvotes: 7

Grayside
Grayside

Reputation: 4194

If you happen to be using the Features module, it has created a solid structure for interacting with the System table that is readily adaptable for any module info gathering.

To get information about a module, use features_get_modules($module_name). This dispatches a module-specific request to features_get_info() on line 475 of features.module.

The information is cached, and you can make use of hook_system_info_alter() to modify the values you need. Note that this functionality is not touched by anything in Drupal core, and is only useful for your own custom module functionality.

Upvotes: 5

Related Questions