line 783: $element['#options'] = $empty_option + $element['#options'];
should be $element['#options'] = $empty_option + (array)$element['#options'];

Comments

mikemiles86’s picture

Assigned: Unassigned » mikemiles86

The 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:

if (is_array($element['#options']) {
  $element['#options'] = $empty_options + $element['#options'];
} else {
  $element['#options'] = $empty_options;
}
mikemiles86’s picture

Assigned: mikemiles86 » Unassigned
Status: Active » Postponed (maintainer needs more info)
mikemiles86’s picture

Assigned: Unassigned » mikemiles86
mikemiles86’s picture

Assigned: mikemiles86 » Unassigned

This 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:

$element['#options'] = 1234;
$element['#options'] = $empty_options + $element['#options'];

That will generate the error (but you shouldn't be doing this anyway). No matter what else I tried to do:

  • add a select field with no options to a form
  • create a custom module, build a custom form and create a select element with no #options defined

By the time the form element was processed in that method #options was already an empty array.

miksha’s picture

I 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.

miksha’s picture

Problem and solution was within Maestro module. Nothing to do with the core. Sorry.

https://www.drupal.org/project/maestro/issues/3011495

Version: 8.0-alpha10 » 8.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

tim.plunkett’s picture

Version: 8.x-dev » 8.0.x-dev
Status: Postponed (maintainer needs more info) » Closed (works as designed)