- Issue created by @berdir
- Merge request !10970Resolve #3501136 "Explicitly register templatepreprocess" β (Open) created by berdir
- π¨πSwitzerland berdir Switzerland
Created a merge request with a proof of concept, basic right now, but already covers BC by only looking for and registering template_ prefixed functions if initial preprocess is not defined.
MR is based on the referenced issue, only relevant changes is the currently last commit: https://git.drupalcode.org/project/drupal/-/commit/a955017c8e669d28297af....
Array key "initial preprocess" obviously up for discussion, I picked this to explain the difference to regular preprocess functions.
I copy pasted the invocation, we can for example use\Drupal\Core\Utility\CallableResolver to also support services.
- πΊπΈUnited States nicxvan
We discussed this briefly on slack, so I'd like to move some thoughts here.
#3495943: Handle module preprocess functions as OOP hooks is struggling a bit with that and need to introduce the ability for modules to register them as hooks but not for themself but a "template" pseudo-module.
I'd disagree with the characterization that it is struggling, it is solved. I'm not sure I'd call it a pseudo module either, it's a prefix, it's basically the same thing Registry does for it.
As for this issue:
I think it's an interesting approachuse\Drupal\Core\Utility\CallableResolver to also support services.
I think we'd definitely want to do this, it would be a shame to have DI for other preprocess hooks but not these ones.
This does make theme_registry_alter harder to maintain BC for contrib which is not a problem for the original issue, but I'm not sure how many people are moving template preprocess around, and I'm not sure this should be a blocker for this approach, just an observation.
Another thing I see is this relies on call_user_func_array for calling the initial preprocess, I am not a fan of that call, the original approach only uses it for fallback for custom callbacks added in theme registry alter.
If it's decided that this is the direction to go, I really think this should be done together with the other issue, this isn't too much more and if we pull out the template work in the other issue the changes are likely a wash complexity-wise.