Numeric content inside square brackets within a node body recognised as a token with a type of int

Created on 29 May 2024, over 1 year ago

Problem/Motivation

I have a piece of content that requires a time format to be entered within square brackets. Examples are [16:00] and [12:00].

This is being recognised as a token with a type of int, however Drupal\Core\Utility\Token->generate() requires the type to be a string.

Steps to reproduce

* Install Drupal 10.1.x
* Install and enable the token_filter module.
* Install and enable the hux module.
* Create a custom module with a very basic hook_tokens().
* Create a basic page with some content including [16:00] and [12:00].
* Save the page, and attempt to view it.
* You'll be presented with a TypeError - Argument #1 ($type) must be of type string, int given.

Proposed resolution

In the doReplace() method of Drupal\Core\Utility\Token, cast the first argument to a string.
$replacements += $this->generate((string) $type, $tokens, $data, $options, $bubbleable_metadata);

Remaining tasks

* Create a failing test.
* Create patch.
* Ensure test is passing.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

🐛 Bug report
Status

Active

Version

10.1

Component
Token 

Last updated about 2 months ago

No maintainer
Created by

🇦🇺Australia hoffismo Brisbane, Queensland

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024