Incorrect type hinting in the smart_trim_tokens function

Created on 9 October 2024, 6 months ago

Ran into an issue...user wants to put a timestamp in their body text like [12:57] - this is being seen as a token by smart_trim and all other modules that look for tokens, but long story short my error:

"smart_trim_tokens(): Argument #1 ($type) must be of type string, int given"

I went to that function which is using HOOK_tokens and see the $type is expecting a string, but if I look at the core HOOK_tokens, the $type argument is not hinted. If we remove this hint, my error goes away. All other contrib modules I looked at are not type-hinting this argument either, so I say we follow the core example which is:

function hook_tokens($type, $tokens, array $data, array $options, \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata) {}

Looks like smart_trim is hinting the $tokens argument as well, so we could remove that as well.

🐛 Bug report
Status

Active

Version

2.2

Component

Code

Created by

🇨🇦Canada porchlight

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

Comments & Activities

Production build 0.71.5 2024