Problem/Motivation

When using devel module to view tokens on an entity containing a custom field (path /devel/token/[entity_type]/[entity_id]), I see

TypeError: explode(): Argument #2 ($string) must be of type string, int given in explode() (line 433 of modules/composer/custom_field/src/Hook/TokenHooks.php).

The argument in question is an array key retrieved with findWithPrefix(). In the event that a token is of the format [entity:some_custom_field:0], the key would be "0", which PHP silently changes to 0, breaking the explode() call.

Proposed resolution

Cast the key as a string when calling explode().

Remaining tasks

Make a MR.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

benstallings created an issue. See original summary.

benstallings’s picture

Assigned: benstallings » Unassigned
Status: Active » Needs review
apmsooner’s picture

Status: Needs review » Fixed

I was able to reproduce the bug and confirm the fix works. Thanks Ben!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

apmsooner’s picture

Status: Closed (fixed) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.