Wrong type declaration for $callback in Drupal\Core\Security\StaticTrustedCallbackHelper::callback()

Created on 9 September 2024, 4 months ago

Problem/Motivation

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)..

Steps to reproduce

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'];

πŸ› Bug report
Status

Closed: works as designed

Version

10.3 ✨

Component
DatetimeΒ  β†’

Last updated 6 days ago

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024