Problem/Motivation

The following hooks can be OOP if we change how they are invoked

  • hook_module_preinstall
  • hook_module_preuninstall
  • hook_modules_installed
  • hook_modules_uninstalled
  • hook_cache_flush

Are all invoked using invokeAll during module install.
Since these are all acting on already installed modules we can replace the moduleInstaller invoke with moduleHandler invoke

Steps to reproduce

Convert a hook
Install a module
Uninstall a module
See hooks did not run

Proposed resolution

  1. Invoke moduleHandler->invoke instead of module installer's invoke in module installer's invoke all
  2. Remove procedural only block
  3. update documentation

Remaining tasks

Update the original OOP hook CR to remove it from the list of unsupported hooks.
https://www.drupal.org/node/3442349
Publish CR with this too

User interface changes

N/A

Introduced terminology

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

Issue fork drupal-3486462

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

nicxvan created an issue. See original summary.

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Title: Fix invocation of hook_module(s)_(pre(un))install(ed) so they support OOP hooks » Fix invocation of hook_module(s)_(pre(un))install(ed) and hook_cache_flush so they support OOP hooks
Issue summary: View changes

nicxvan’s picture

Preinstall Triggers this:

 if (!$this->moduleHandler->isLoaded() && !defined('MAINTENANCE_MODE')) {
      throw new \Exception('The theme implementations may not be rendered until all modules are loaded.');
    }

In themeManager

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Title: Fix invocation of hook_module(s)_(pre(un))install(ed) and hook_cache_flush so they support OOP hooks » Support several hooks called by ModuleInstaller
Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Title: Support several hooks called by ModuleInstaller » Support #Hook for several hooks called by ModuleInstaller
Status: Active » Needs review
nicxvan’s picture

Status: Needs review » Needs work
nicxvan’s picture

Issue summary: View changes
Status: Needs work » Needs review
nicxvan’s picture

Issue summary: View changes
catch’s picture

Status: Needs review » Reviewed & tested by the community

This looks really tidy and well scoped. The genuinely weird install hooks are left as is, just the 'normal' hooks that happens to be about installing modules converted, actual code change is a few characters. RTBC for me.

  • larowlan committed 5330cfd8 on 11.1.x
    Issue #3486462 by nicxvan: Support #Hook for several hooks called by...

  • larowlan committed 2c9e1fa9 on 11.x
    Issue #3486462 by nicxvan: Support #Hook for several hooks called by...

larowlan’s picture

Version: 11.x-dev » 11.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed to 11.x and backported to 11.1.x

Published change notice

nicxvan’s picture

Thank you so much! I'll update the CR for #3442009: OOP hooks using attributes and event dispatcher to reflect the hooks that are now available since that issue has more visibility.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.