Closed (outdated)
Project:
Drupal core
Version:
7.x-dev
Component:
forms system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
29 Oct 2018 at 02:26 UTC
Updated:
31 Dec 2019 at 06:31 UTC
Jump to comment: Most recent
Comments
Comment #2
keithgcochran commentedI've resolved this issue for now by adding a check for an empty array.
form.inc method form_type_checkboxes_value:
WAS:
function form_type_checkboxes_value($element, $input = FALSE) {
if ($input === FALSE) {
$value = array();
$element += array('#default_value' => array());
foreach ($element['#default_value'] as $key) {
$value[$key] = $key;
}
return $value;
}
...
NOW:
function form_type_checkboxes_value($element, $input = FALSE) {
if ($input === FALSE) {
$value = array();
$element += array('#default_value' => array());
if (!empty($element['#default_value'])) { // check for empty array before using
foreach ($element['#default_value'] as $key) {
$value[$key] = $key;
}
}
return $value;
}
...
Comment #3
alex-b commentedAn empty array is a valid argument for
foreach. I suspect your fix works because the#default_valuefor the affected checkboxes element is set to another 'empty' value somewhere outsideform_type_checkboxes_value(), e.g.0orFALSE. Can you check the if the element which triggers the warning has a#default_value?