- Issue created by @morvaim
- Status changed to Closed: works as designed
4 months ago 10:56am 9 September 2024 Ok, I realized a callable can be an array of a class and a method name, so I don't know why I get this error message.
https://www.drupal.org/project/drupal/issues/3213572 β
introduced Drupal\Core\Security\StaticTrustedCallbackHelper
class, so when a callback is added as #date_time_callbacks
or #date_date_callbacks
\Drupal\Core\Security\StaticTrustedCallbackHelper::callback
is called and the callable is passed to it as argument. But because the $callable
argument's type is declared as `callable` it is impossible to add a callable as a method of a class which implements \Drupal\Core\Security\TrustedCallbackInterface
which is the recommended way to add callbacks, because the following error is thrown: TypeError: Drupal\Core\Security\StaticTrustedCallbackHelper::callback(): Argument #1 ($callback) must be of type callable, array given, called in /mnt/files/local_mount/build/web/core/lib/Drupal/Core/Datetime/Element/Datetime.php on line 275 in Drupal\Core\Security\StaticTrustedCallbackHelper::callback() (line 43 of /mnt/files/local_mount/build/web/core/lib/Drupal/Core/Security/StaticTrustedCallbackHelper.php).
.
Add a a new callback to a Datetime element's #date_time_callbacks
or a #date_date_callbacks
as a method of a class which implements \Drupal\Core\Security\TrustedCallbackInterface
then try to check the form where the Datetime element is present.
E.g.: $form['datetime']['#date_date_callbacks'][] = [DatetimeCallback::class, 'dateDateCallback'];
Closed: works as designed
10.3 β¨
Last updated
Ok, I realized a callable can be an array of a class and a method name, so I don't know why I get this error message.