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:
11 Sep 2018 at 15:41 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 commented