Active
Project:
Drupal core
Version:
main
Component:
base system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
2 Jul 2018 at 09:01 UTC
Updated:
6 Aug 2026 at 21:09 UTC
Jump to comment: Most recent
Right now there are various places that allow developers to specify a some kind of callback or method as part of defining some behaviour. A few examples are:
allowed_values_functionFieldConfigInterface::setDefaultValueCallback#process#after_build#pre_render#lazy_builderThere are a bunch of ways to capture a callback and invoke it. A few are:
current_user:id)controller_resolver service, to support functions, static methods and service notation)CallbackResolver as named here into various subsystems that might need it
Comments
Comment #2
sam152 commentedComment #3
joachim commentedOne of the problems we face in unifying this is that different places use 'ThisClass::thisMethod' to mean different things.
In FieldConfigInterface::setDefaultValueCallback(), a value of 'ThisClass::thisMethod' simply is a PHP callable, representing a static call to thisMethod() on the class ThisClass.
However, in the routing system, putting 'ThisClass::thisMethod' as the controller for a route will cause ControllerResolver to use the DI ClassResolver to instantiate ThisClass, and call thisMethod() on the instance:
So given that, I think our new CallbackResolver will need two public methods, one for each behaviour: resolveCallbackWithStatic(), and resolveCallbackWithInstantiation()
Comment #4
sam152 commentedAny chance you could review #2982949: Introduce CallableResolver to help standardise the DX and error handling for callbacks across various subsystems and we could have the discussion there?
Comment #6
sam152 commentedComment #7
joachim commentedComment #8
joachim commentedComment #9
joachim commentedComment #20
avpadernoComment #21
cyb_tachyon commented#3259716: Replace usages of static::class . '::methodName' to first-class callable syntax static::method(...) issue gets into this, but currently TrustedCallback attributes / object->callback design breaks serialization for render arrays.
This can be seen in the core layout_builder module, which uses a TrustedCallback for pre-render. This breaks any render caching of the layout_builder element when cached in-memory.
Example: Install a Drupal Site from existing config with layout_builder enabled.
This isn't necessarily an emergency, as it's well know that --existing-config site installs are very easily broken by many contrib modules, but layout_builder is in Core.
Open Questions
I'd like to change the Issue summary to include this scope. Can someone recommend either: a separate issue to bubble to this Meta issue, or attaching to this issue that only covers #after_build and not all serializable element callbacks #3424106: Using a closure in #after_build may result in a "Serialization of 'Closure' is not allowed" exception ?