Implement HuxModuleHandler::resetImplementations() as a public way to trigger discovery of hook classes?

Created on 11 November 2023, 8 months ago
Updated 14 November 2023, 8 months ago

Problem/Motivation

I tried to write a kernel test where a module that implements a Hux hook class isn't installed initially (i.e. not present in KernelTestBase::$modules so that I could install the module partway into a test to verify that the hook does indeed take effect, i.e. compare the values without the module against the values with the module installed. I've tried so many things in the test, including forcing a container rebuild, deleting various caches including the bootstrap bin, but none of seem to result in the hook taking effect. It works perfectly if I include the module in KernelTestBase::$modules, but that defeats part of the goal of the test. I tried following the proverbial breadcrumbs and trying to see if there's anything special that KernelTestBase does with that property, but couldn't get the hook to take effect.

Steps to reproduce

See above.

Proposed resolution

Not sure, but I think some public method to force discovery of Hux hooks would be super handy in this and other instances, because a lot of the discovery code in Hux seems to be internal and there's no clear way to do this without a number of hacks or relying on internal stuff that can break at any time. ModuleHandlerInterface::resetImplementations() seems to exist for this purpose for procedural hooks, which at first glance one would assume would also trigger Hux discovery, but it looks like the call just gets passed to the decorated module handler service. Could that method on HuxModuleHandler also perform Hux hook class discovery?

Granted, that wouldn't solve the underlying issue but would at least provide a failsafe button code can hit if situations like this arise as a short term workaround.

Remaining tasks

Here be dragons.

User interface changes

None.

API changes

Maybe something minor added, or none at all.

Data model changes

None?

πŸ’¬ Support request
Status

Closed: won't fix

Version

1.2

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada Ambient.Impact Toronto

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Ambient.Impact
  • πŸ‡¨πŸ‡¦Canada Ambient.Impact Toronto

    Kind of related issue in the sense it deals with automatic discovery of hook classes I suppose.

  • πŸ‡¦πŸ‡ΊAustralia dpi Perth, Australia

    Per my comments in the linked issue, I think I still want to try to tack on Hux' data onto the container in some way such that if it is invalidated/destroyed then the Hux data is naturally rebuilt. I'd prefer to not make a public API to this. Leaning to close this in favor of the other unless we come to some other agreement.

  • πŸ‡¦πŸ‡ΊAustralia dpi Perth, Australia

    The results of discovery aren't supposed to change unless Drupal's extension list changes.

    So if you've got optimise=on, then you'll need to do a full system cache clear just like you would if you were introducing a new Hooks class in an already installed module.

    If optimise=off then its just being sticky about the container, you're in Kernel tests so some crafty ways of getting around it are needed.

    You could try something as simple as using moduleinstaller to install Hux then check if your hooks are available. Anything more than that then I'd say you may be overtesting.

  • πŸ‡¨πŸ‡¦Canada Ambient.Impact Toronto

    I think you're right and ideally this should just automagically work. I ended up just implementing the test with Hux already installed and it's good enough for our purposes.

    So if you've got optimise=on, then you'll need to do a full system cache clear just like you would if you were introducing a new Hooks class in an already installed module.

    In general, I tend to avoid clearing caches in production unless totally necessary, as at least one of my sites has some pretty complex content that can be expensive to render, both in terms of time from a cold cache and also since we have background tasks that warm those caches as needed. We rely on rebuilding specific things or via container rebuilds on deployment rather than nuking the whole cache. I even built and maintain a small contrib module specifically to quickly and easily rebuild everything from the container to library definitions, the router, and so on β†’ .

    Is it possible to have the performance benefits of optimized mode, small though they may be, without having to do a full cache clear if new or changed hook classes are introduced? Our container mostly only gets rebuilt on deploy (via the deployment identifier) and very rarely otherwise.

  • πŸ‡¦πŸ‡ΊAustralia dpi Perth, Australia

    Is it possible to have the performance benefits of optimized mode, small though they may be, without having to do a full cache clear if new or changed hook classes are introduced?

    Yeah, thats where adding this data to the container instead of cache bins comes in.

  • Status changed to Closed: won't fix 8 months ago
  • πŸ‡¨πŸ‡¦Canada Ambient.Impact Toronto

    Makes sense. Going to close this in favour of the other issue and will help out there if I'm able to. Let me know if there's something specific I can contribute.

  • πŸ‡¦πŸ‡ΊAustralia dpi Perth, Australia

    Let me know if there's something specific I can contribute.

    Researching an efficient mechanism to store huxdiscovery into the container is the main thing. Help appreciated.

Production build 0.69.0 2024