Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
line 783: $element['#options'] = $empty_option + $element['#options'];
should be $element['#options'] = $empty_option + (array)$element['#options'];
Comments
Comment #1
mikemiles86The line number listed in the issue summary is incorrect.
I believe the code in question lives on line 874.
Before creating a patch for this fix, it would probably be beneficial to list steps on how to recreate.
Instead of typecasting $element['#options'] as an array, should we instead first check to see if it is an array and then prepending empty_options?
Something like:
Comment #2
mikemiles86Comment #3
mikemiles86Comment #4
mikemiles86This code is part of the form_process_select() method, which handles select fields in forms. The only way I have been able to recreate this issue is to hack core (ack!) and right before the line in question (line 874) set $element['#options'] into something else other than an array.
Example:
That will generate the error (but you shouldn't be doing this anyway). No matter what else I tried to do:
By the time the form element was processed in that method #options was already an empty array.
Comment #5
miksha CreditAttribution: miksha commentedI came here searching for the same error but using Drupal 7.59. I had this issue with using Rules and Maestro modules:
https://www.drupal.org/project/rules/issues/3011448
Changing line 2760 inside includes/form.inc file from:
$element['#options'] = $empty_option + $element['#options'];
to:
$element['#options'] = $empty_option + (array)$element['#options'];
makes this error go away.
Comment #6
miksha CreditAttribution: miksha commentedProblem and solution was within Maestro module. Nothing to do with the core. Sorry.
https://www.drupal.org/project/maestro/issues/3011495
Comment #8
tim.plunkett