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.
I get "Warning: Illegal offset type in _multiselect_build_widget_code on line 246":
$selected_options[$value['target_id']] = $value['target_id'];
Explicitly casting the value to a string before using it as the key fixes the problem:
$selected_options[(string)$value['target_id']] = $value['target_id'];
Comment | File | Size | Author |
---|---|---|---|
#4 | multiselect-multiselect_build_widget_code-2445981-4-D7.patch | 865 bytes | Proteo |
#3 | multiselect-multiselect_build_widget_code-2445981-3-d7.patch | 911 bytes | ntsekov |
Comments
Comment #1
DrCord CreditAttribution: DrCord commentedAfter further testing this appears to be due to ajax happening on an ubercart order page that uses the multiselect widget for an added field. The target id is NULL when the multiselect list selected items are empty.
I realized a better solution would be to never enter the control structure with a weird value that will cause issues, but instead to set the array to an expected input value if it is weird...
so adding these lines at the first line of the function _multiselect_build_widget_code seems to be a better solution:
Comment #2
DrCord CreditAttribution: DrCord commentedAfter further testing, during ajax calls when the values are set they are returned nested too deep also. This code is also needed:
change:
to:
Comment #3
ntsekov CreditAttribution: ntsekov commentedHere is the patch.
Comment #4
Proteo CreditAttribution: Proteo as a volunteer commentedHi, I'm having the very same problem but with a different source (a taxonomy field) and the Autosave module, wich also makes an AJAX request when restoring previously saved values. Not sure If I should open a new issue, but since this is basically the same problem I think we could handle it here.
The problem is that the value is sent not as a string but as a nested array, for example:
I think a way to address the issue is to make sure that the value passed to the $selected_options array has been flattened in a more generic way, such as:
Patch against the 7.x-1.x branch is provided.