I want to get the human name from the machine name for an extension (i.e. a module or a theme).
I know that I can do this for a module by this call:
$human_name = \Drupal::service('extension.list.module')->getName('automated_cron');
This will return the human name for core Automated Cron module.
To do the same thing for a theme, I can invoke the service 'extension.list.theme'
.
Is there something that will provide this information and not care whether the extension is a module or a theme?
In my current implementation, I use this workaround:
$extension_name = 'automated_cron';
if (\Drupal::service('module_handler')->moduleExists($extension_name)) {
$human_name = \Drupal::service('extension.list.module')->getName($extension_name);
}
else {
$human_name = \Drupal::service('extension.list.theme')->getName($extension_name);
}
dpm($hunan_name, 'human name');
Is there a simpler way to get the desired result (i.e. without using an if-test)?