- Issue created by @bircher
- 🇦🇺Australia dpi Perth, Australia
It seems like an odd usage, adding hook definitions in services defined by a container YAML.
Presently you should be able to define more namespaces to expand on `\Drupal` in your own custom directories. Then use the `hooks` service tag like hux_test.services.yml. That should get you going with container YAMLS.
I've renamed the issue accordingly. Let me know if this isnt right.
As for supporting arbitrary namespaces, I'm open to the idea so long as we have tests. The regex detection stuff in HuxCompilerPass is the primary concern. This could be resolved with service tags or PHP attributes indicating a module name. In the end we need to associate each hook definition with a module, since core ModuleHandler requires it.
This is certainly not something I'm planning on working on any time soon, so if you have some time to contribute that would be appreciated.
- 🇨🇭Switzerland bircher 🇨🇿
Cool! Thanks for the reply!
Yes I know that the module handler needs it, but from my tests the module handler doesn't care if the module exists or not.
My workaround is to define a dev-PSR4 namespace in the root composer.json for \Drupal\mytests and then add a tests.services.yml that defines the services I need in my tests there. (I use it mostly to decorate/replace services interacting with third party APIs to log their interaction instead.) I created this issue because using a hook to alter some things was easier because it is not with a system easily pluggable with services.
Usually my test services don't live in \Drupal\something but in \MyCode\something since they are not from a module. (Of course i could put all of this in a module and just install the module in the test environment too.. but then I would have a test module one could technically install on prod, while the dev-PSR4 namespace is just not loaded and one can not edit settings.php from the admin UI to add the services.yml)As for implementation, we could require another tag on such services like
hook_module
and throw the exception only when it doesn't have that. - 🇦🇺Australia dpi Perth, Australia
Would make sense as an attribute. Something like #[AsModule], with TARGET_CLASS.
Similar to how
\Drupal\hux\Attribute\ReplaceOriginalHook
can specify a$moduleName
.