Read the following comment, from system.module:
/**
* Execute the system_settings_form.
*
* If you want node type configure style handling of your checkboxes,
* add an array_filter value to your form
*
*/
function system_settings_form_submit($form_id, $values) {...What does this comment mean? Here's what I think it means. When you are writing the settings hook for a module that can be applied to various node types, you want checkboxes like
page [ ]
story [ ]But the settings don't save properly because of form problems with checkbox values. So the comment is instructing you to add an array_filter element to your form; it is picked up in the code ca. line 789:
if (is_array($value) && isset($values['array_filter'])) {
$value = array_keys(array_filter($value));
}
After some trial and error, I got the saving of checkbox values for node types to work by defining the form element $form['array_filter'] = array('#type' => 'hidden'); (the #value key is not actually used; it's only checking if the key is set).
So to clarify this cryptic comment, I propose adding an example to the comment as follows:
/**
* Execute the system_settings_form.
*
* If you want node type configure style handling of your checkboxes,
* add an array_filter value to your form, e.g.,
* $form['array_filter'] = array('#type' => 'hidden');
*
*/
function system_settings_form_submit($form_id, $values) {...chx, is this what the comment means? FYI, It was originally added here.
| Comment | File | Size | Author |
|---|---|---|---|
| settings_example.diff | 667 bytes | jvandyk |
Comments
Comment #1
jvandyk commentedTalked to chx, he was in agreement.
Comment #2
dries commentedFrankly, I don't understand what "node type configure style handling" means, or why it is a special case. Sounds like an ugly hack. While the proposed description is better, it is still too obscure.
Comment #3
dries commentedComment #4
robertdouglass commentedWhy is the check for array_filter there anyway? What bad thing happens if it isn't there?
Comment #5
jvandyk commentedAssume a basic settings form with checkboxes for node types:
This is a simple checkbox form that stores the results in the Drupal variable foo_nodetypes. With the array_filter line included, the variable stores:
Comment out the array_filter line and the variable stores
Storing the first is preferred because with many nodetypes you're transferring more unneccesary data from the database on each request.
Comment #6
Chill35 commentedIt is an ugly hack.
What's happening to this anyway...?
Comment #7
ragaskar commentedWow. that is a little confusing. Glad this page is the first result for 'array_filter system_settings_form' on google, otherwise I'd probably be scratching my head for another hour over the phrasing of that on the api ref. (as it is, I'm still unsure whether or not i'll need to include a filter).
Is it possible to at least point people here in the interim from that docpage? Might save a couple people some headaches.
Comment #8
dave reidAlso see #315176: Clean-up remains of $form['array_filter'] hack with array_filter in book module.
Comment #9
marcingy commentedbumping version
Comment #10
dave reidWe should handle this with #315176: Clean-up remains of $form['array_filter'] hack with array_filter in book module.