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.
select_or_other seems to be a constant source of notices "Undefined index #other…". To avoid that we should define default values in hook_element_info() for all properties that are then used in select_or_other_element_process().
Comment | File | Size | Author |
---|---|---|---|
#5 | 2560385-select_or_other-defaults-in-hook_element_info-5.patch | 2.75 KB | torotil |
Comments
Comment #2
torotil CreditAttribution: torotil at more onion commentedHere is a quick patch that defines defaults to fix the two most common notices for my sites.
todo:
Comment #3
legolasboThanks for your patch, let's complete the list of defaults and get this committed.
Comment #4
torotil CreditAttribution: torotil at more onion commentedThis patch makes the following changes:
First I changed the part of the code that transfers the #properties from $element to $element['select'] to only transfer the properties that are present. After that the following #properties were still used (without checking for existence) in select_or_other_element_process(): #default_value, #options, #other_unknown_defaults, #other_delimiter, #multiple, #other, #attributes, #select_type.
This means that #attributes, #options, #other_unknown_defaults and #other_delimiter were missing. This patch defines them as follows:
Additionally processing related to #disabled can be dropped. It is propagated to child-elements automatically by form_builder(). The special case for #other_size is already handled by the loop a few lines above and can be dropped.
Comment #5
torotil CreditAttribution: torotil at more onion commentedForgot to attach the patch.
Comment #6
torotil CreditAttribution: torotil at more onion commentedComment #7
legolasboI don't see a default setting for #size. Doesn't this cause notices if #size isn't set?
Let's follow core's coding standards here and either put all values on the same line, or one value per line.
I would also like to see test coverage for this.
Comment #8
torotil CreditAttribution: torotil at more onion commentedThe line with #size is removed in my patch - so no this won't throw notices ;)
Both true - I'd love to see test coverage too. But it seems that that's the limit of time that I can invest at this point. If you want anything more you'll need to find someone else to do it. BTW: this function seems to be perfectly unit-testable which is rather seldom in the Drupalverse.
Good luck!
Comment #9
legolasbo@torotil,
Thanks for your effort so far! I'm not sure when I have time to complete the work, but your efforts are greatly appreciated.
Comment #10
rimu CreditAttribution: rimu commentedWorks for me. :D
Comment #11
daften CreditAttribution: daften at Dropsolid commentedClosing as outdated because no activity in a long time and Drupal 7 goes EOL soon. Feel free to re-open if needed.