- Status changed to Needs work
8 months ago 11:29am 15 April 2024 - 🇮🇹Italy apaderno Brescia, 🇮🇹
+ if (isset($field_type_info['default_widget'])) { + $default_widget = $field_type_info['default_widget']; + } else { + $default_widget = NULL; + } // Fill in default values. $widget += array( - 'type' => $field_type_info['default_widget'], + 'type' => $default_widget, 'settings' => array(), 'weight' => 0, ); @@ -585,10 +590,14 @@ class FieldInfo { $widget_type_info = field_info_widget_types($widget['type']);
When
NULL
is passed tofield_info_widget_types()
, it returns an array containing information for all the widget types. This would cause errors in the rest of the code, which expects an array with information about a single widget type.function field_info_widget_types($widget_type = NULL) { $info = _field_info_collate_types(); $widget_types = $info['widget types']; if ($widget_type) { if (isset($widget_types[$widget_type])) { return $widget_types[$widget_type]; } } else { return $widget_types; } }
Notice that Trying to access array offset on value of type null means trying to access
$field_type_info['default_widget']
when$field_type_info
isNULL
, which means thatfield_info_field_types($field_type)
in$field_type_info = field_info_field_types($field_type);
returnedNULL
.
That happens when the field type passed as argument is not known to Drupal. At this point, it is not possible to know which is the default widget type for the field, since not even the field type is known.NULL
is not a valid widget type, and it should not be used.