Problem/Motivation

When using Redirect after logout in conjunction with Hook event dispatcher, a TypeError is thrown when accessing its configuration form :

TypeError: Drupal\redirect_after_logout\Form\RedirectLogoutSettings::__construct(): Argument #3 ($module_handler) must be of type Drupal\Core\Extension\ModuleHandler, Drupal\hook_event_dispatcher\HookEventDispatcherModuleHandler given, called in /app/web/modules/contrib/redirect_after_logout/src/Form/RedirectLogoutSettings.php on line 78 in Drupal\redirect_after_logout\Form\RedirectLogoutSettings->__construct() (line 59 of modules/contrib/redirect_after_logout/src/Form/RedirectLogoutSettings.php).

Because Hook event dispatcher overrides the ModuleHandler service, a HookEventDispatcherModuleHandler is returned.

Steps to reproduce

Install both modules and access the config form at /admin/config/system/redirect_after_logout

Proposed resolution

The RedirectLogoutSettings form incorrectly uses ModuleHandler as a dependency, it should use ModuleHandlerInterface.

The attached patch addresses this by replacing the concrete class with the interface.

Note: Other services could similarly be swapped for their interfaces, but this has been left out of scope and should be addressed in a separate issue.

Comments

manu manu created an issue. See original summary.

akashkumar07’s picture

Status: Needs review » Needs work

Hi @manu-manu,
We also need to update the @var path for $moduleHandler

 /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

Rest changes look good.

If you want, i will be happy to create an MR for this issue fix.

Thanks!