several contrib modules fail to comply with FAPI #access property
when an element of #type=checkboxes has #access=FALSE
usually modules expect to receive data like:
array(
7 => 7, // checked
13 => 0, // unchecked
21 => 21, // checked
)
but when a form is altered, and #access turned into FALSE, data comes like:
array(
7 => 1, // checked
13 => 0, // unchecked
21 => 1, // checked
)
therefore, common code doing an array_filter and keeping the values (instead of the keys) use to fail,
instead they should prevent this by doing drupal_map_assoc(array_keys(array_filter($values))) [sigh]
the biggest problem being, that most modules work fine until they are required to play nicely with other 3rd party code altering #access rules
therefore, security alterations use to introduce bugs, instead of the intended FAPI Access Control
where does this come from?
function expand_checkboxes doing '#default_value' => isset($value[$key]),
as you will notice, this was already fixed in D7 counterpart
function form_process_checkboxes by means of '#default_value' => isset($value[$key]) ? $key : NULL,
bringing sanity back to those checkboxes with #access=FALSE which will enter form_type_checkbox_value with $edit being FALSE and end up returning the #default_value
Comments
Comment #1
alan d. commentedSubs. This is still an issue in D6.
The older issue related to multiforms is probably a duplicate, #187413: Forms API MultiStep w/ Checkboxes: can't set default values, and in contrib, #767060: Hide field breaks checkboxes, #765962: Cannot assign default values to checkboxes when #access is set to FALSE probably many others
A fast workaround is to change the type from checkboxes to select, but this makes me worried about all those forms that we have simply thrown in an #access flag without care for the internal elements.
Bumping to major as god knows what settings this bug is nuking in the process!
Comment #2
arhak commented3rd party modules pay the price, e.g. #1114402: Support for FAPI #access=FALSE
Comment #3
fourmi4x commentedSubscribing, this is kind of critical...!
For those looking for a temporary solution, http://drupal.org/node/765962#comment-2897746 contains a quick workaround.