Drupal get module info?
Is there any fun开发者_如何学Pythonction in Drupal like get_module_info('MODULE_NAME')
or I should parse info
file?
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);
A somewhat easier method (drupal 7 and up) is to use the system_get_info function.
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.
精彩评论