Problem/Motivation

OOP hooks are coming.
Install hooks are particularly problematic.
Ghost of Drupal Past has a POC for adding the namespace.
https://www.drupal.org/project/drupal/issues/3442009#comment-15757035
Also see:
https://www.drupal.org/project/drupal/issues/3442009#comment-15754774
And:
https://www.drupal.org/project/drupal/issues/3442009#comment-15755910

Steps to reproduce

Proposed resolution

Determine if this should be split into multiple followups. The followups do not need to follow a particular order, but they were split up here for clarity.

Followup 1: Invoked in ModuleInstaller using ModuleHandler: All completed

Hooks that likely just need verification (convert an implementation and confirm it works)
These were excluded for scope on #3442009: OOP hooks using attributes and event dispatcher
#3486462: Support #Hook for several hooks called by ModuleInstaller

  • hook_module_preinstall
  • hook_module_preuninstall
  • hook_modules_installed
  • hook_modules_uninstalled
  • hook_cache_flush

Followup 2: Theme Hooks in modules: All completed

Add new method on ModuleHandlerInterface to check for the existence of a hook
When the theme registry is built there is a hook check instead of function_exists.
The theme registry structure may need a change to store the module name so when ThemeManager fires them it can call them via ModuleHandler if it is a module implementing them similar to how the parent issue split hook_theme.

Followup 3 Hooks called by ModuleInstaller, Update system, and Drupal installer (except hook_requirements)

Additional notes from Ghost:
We can add the module's namespace to the classloader then rebuild the container.
The issue is if during container rebuild anything fires a hook in the module to be installed (for example because entity definitions are requested, this is super common) that hook might not work because install did not run yet! Conclusion: install can't be an ordinary hook. The exact same reasoning applies converting install to any sort of service which is registered on the container. So if we can't inject services ... then what's the point of conversion? It could be moved into a magic named class like service provider but that's about it. I am guessing we could pass the container to this new thing so it can request services of already installed modules. (But then again, we could pass the container to hook_install just fine.

Followup 4: Metahooks: All completed

Followup 5: Themes and theme engines: All completed

Remaining tasks

Follow up 3

User interface changes

N/A

Introduced terminology

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Comments

nicxvan created an issue. See original summary.

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

nicxvan’s picture

Title: [PP-1] Explore converting Install hooks to OOP » [PP-1] Explore converting Install and Theme hooks to OOP
Issue summary: View changes
nicxvan’s picture

Title: [PP-1] Explore converting Install and Theme hooks to OOP » [PP-1] Explore converting Install and Theme hook implementations to OOP
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Title: [PP-1] Explore converting Install and Theme hook implementations to OOP » Explore converting Install and Theme hook implementations to OOP
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes

Follow up one hooks are all complete.

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
andypost’s picture

nicxvan’s picture

Can you help me understand how that is related?

nicxvan’s picture

Issue summary: View changes
andypost’s picture

This is related cos planing transition to new hooks would be great to keep it in a mind

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes

Follow up 4 is done!

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Component: base system » extension system
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Title: Explore converting Install and Theme hook implementations to OOP » [Meta] Track converting Install and Theme hook implementations to OOP
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Title: [Meta] Track converting Install and Theme hook implementations to OOP » [Meta] Track support for Install and Theme hook implementations to OOP

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

nicxvan’s picture

Issue summary: View changes