Problem/Motivation
When use link field widget in custom form, start seeing following notice on PHP 7.4
Notice: Trying to access array offset on value of type null in field_widget_instance() (line 625 of /app/web/modules/field/field.form.inc)
Steps to reproduce
With PHP 7.4, use link widget on a custom form, see https://www.drupal.org/project/link/issues/2718563.
Proposed resolution
Instead of calling field_widget_instance() directly in link_field_process(), called field_form_get_state()and check for instance.
function link_field_process($element, $form_state, $complete_form) {
- $instance = field_widget_instance($element, $form_state);
+ $field_state = field_form_get_state($element['#field_parents'], $element['#field_name'], $element['#language'], $form_state);
+ $instance = !empty($field_state['instance']) ? $field_state['instance'] : array();function field_widget_instance($element, $form_state) {
$field_state = field_form_get_state($element['#field_parents'], $element['#field_name'], $element['#language'], $form_state);
return $field_state['instance'];
}| Comment | File | Size | Author |
|---|---|---|---|
| #3 | link-php74-3276037-3.patch | 702 bytes | xlin1003 |
Comments
Comment #2
xlin1003 commentedComment #3
xlin1003 commentedPatched attached to not use the
field_widget_instance()directly. Not sure if it make sense to patch/fix the core as I only see this notice when using link widget on custom form.Comment #4
damienmckennaThis seems reasonable, and all of the tests pass.
Comment #5
damienmckennaComment #7
damienmckennaCommitted. Thank you.
Comment #9
damienmckenna