How to know the module package? I need to know the package of a given module to performs some actions inside the implementation of a custom a drush command. So usually you will find that we will found this information in the module_handler service. But there is not method to get the module package.

So, how can I know the module package?
Maybe another simpler way exists, but after a little digging in the core I found that the modules list (admin/modules) with all the information is retrieve from the _system_rebuild_module_data() function that use the 
info_parser service to retrieve all the module information.

If you want to know the module package you can use this code:

$module_machine_name = 'views';
$module = \Drupal::service('module_handler')-&gt;getModule($module_machine_name);
$module_info = \Drupal::service('info_parser')-&gt;parse($module-&gt;getPathname());
// To use dpm() you need the devel module.
dpm($module_info['package']);


Output:


  Core