Problem/Motivation
It was reported over in Authcache (#2885086: Check to make sure element is an array before checking to see if it needs to be flagged), that the ubercart attributes module adds a form element 'attributes' => NULL when in the add-to-cart form for products which do not have any product attributes.
This is a violation of the form API contract, since elements (i.e. those array entries whose key does not start with a #-character) are expected to contain arrays. As a result any code which uses the core element_children function on the add-to-cart form might produce notices.
Example of an affected form structure:
Array
(
[nid] => Array
[qty] => Array
[actions] => Array
[node] => Array
[attributes] => NULL
[#form_id] => uc_product_add_to_cart_form_39
[#type] => form
[#build_id] => form-pQth...
[form_build_id] => Array
[#token] => uc_product_add_to_cart_form_39
[form_token] => Array
[form_id] => Array
[#id] => uc-product-add-to-cart-form-39
[#method] => post
[#action] => /page-path
[#theme_wrappers] => Array
[#tree] => NULL
[#parents] => Array
[#validate] => Array
[#submit] => Array
[#theme] => Array
[#after_build] => Array
)
Proposed resolution
Do not add the attributes element if there are no product-attributes in the first place.
Remaining tasks
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 2885388-4-fix-NULL-element.diff | 1.42 KB | znerol |
Comments
Comment #2
tr commentedExactly where is this documented?
Comment #3
znerol commenteddrupal_render():
Comment #4
znerol commentedComment #5
tr commentedSee #2885086-9: Check to make sure element is an array before checking to see if it needs to be flagged
Comment #6
tr commentedAlthough this issue has a good explanation of why the fix is needed, I'm marking this as a duplicate of the earlier issue #2750151: Return empty array instead of null for attributes form. I like the fix there better.