Problem/Motivation
At #2926070: Deprecate ModuleHandlerInterface::getName() it is going to replace \Drupal\Core\Extension\ModuleHandlerInterface::getName() with: \Drupal::service('extension.list.module')->getName($module) the problem is that ModuleHandler::getName() returns the name machine name of the module if it does not found the module name. There is even a docblock mentioning it:
/**
* Gets the human readable name of a given module.
*
* @param string $module
* The machine name of the module which title should be shown.
*
* @return string
* Returns the human readable name of the module or the machine name passed
* in if no matching module is found.
*/
public function getName($module);
And \Drupal::service('extension.list.module')->getName($module) triggers an exception if the module does not exists.
So, starting on Drupal 8.6 this is causing a WSOD whenever a non-existent module is passed to ModuleHander::getName()
Proposed resolution
The posible solutions:
Rewrite the docblock reflecting this change at ModuleHandler::getName() and write a change recordMake\Drupal::service('extension.list.module')->getName($module)returns the machine name if the module does not exists.- Catch the
\Drupal::service('extension.list.module')->getName($module)exception and return the expected value atModuleHandlerInterface::getName()
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3012962-2.patch | 3.01 KB | gnuget |
| #2 | 3012962-tests-only-2.patch | 2.37 KB | gnuget |
Comments
Comment #2
gnugetI've been thinking about this and we can't just edit the docblock because this is a public function, this means that this is breaking the backward compatibility even if the method is going to be deprecated soon.
So, I edited a bit the method to catch the exception and return the expected value and added two tests.
Patch attached.
Comment #5
gnugetThis has been fixed at #3000677: Fatal error after upgrade to 8.6x [due to regression in extension system] :-)
Comment #6
gnuget