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 record
  • Make \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 at ModuleHandlerInterface::getName()

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#2 3012962-2.patch3.01 KBgnuget
#2 3012962-tests-only-2.patch2.37 KBgnuget

Comments

gnuget created an issue. See original summary.

gnuget’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new2.37 KB
new3.01 KB

I'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.

The last submitted patch, 2: 3012962-tests-only-2.patch, failed testing. View results

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

gnuget’s picture

Status: Needs review » Closed (duplicate)
gnuget’s picture