implode should be checking if the variable is an array

Created on 12 October 2022, over 1 year ago
Updated 13 February 2023, over 1 year ago

Problem/Motivation

On web/core/lib/Drupal/Core/Form/FormElementHelper.php, inside function getElementByName, it's doing an implode to a variable, but that variable might not be an array. I'm not sure if this is a bug but I thought I would report it just in case.

If I change this line:
if (implode('][', $form[$key]['#parents']) === $name)

To this:
if (is_array($form[$key]['#parents']) && implode('][', $form[$key]['#parents']) === $name)

Then, it works again.

Steps to reproduce

I'm using module commerce and submodule promotion. When adding a wrong code, this message should appear:
The provided coupon code is invalid

I can only make the error message work when doing the change above.

This is the error I get in watchdog:
TypeError: implode(): Argument #1 ($pieces) must be of type array, string given in implode() (line 32 of /var/www/html/drupal/web/core/lib/Drupal/Core/Form/FormElementHelper.php)

πŸ’¬ Support request
Status

Closed: outdated

Version

9.5

Component
FormΒ  β†’

Last updated about 4 hours ago

Created by

πŸ‡ͺπŸ‡ΈSpain guardiola86

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024