domain_batch_form assumes your dealing with a single form elements (textfield, select, etc).
I trying to support different Social Networking links configuration for different countries, using the service_links module. Which is a typical use case. China likes Sina Weibo, Renren, Tencent, etc. I was able to construct a service_links_domain_batch function. The trick was to use a Fieldset with #tree = FALSE.
/*
* Implements hook_domain_batch()
* - Allows modules to expose batch editing functions, for site administrators to perform bulk updates
*/
function service_links_domain_batch () {
$batch['service_links_show'] = array(
'#form' => service_links_service_links_show_form(),
'#system_default' => array(), // Used to fill the #default_value parameter
'#meta_description' => t('Edit service_links setting value.'),
'#override_default' => TRUE, // use variable_get() to retrieve the current value
'#domain_action' => 'domain_conf', // domain_conf table.
'#variable' => 'service_links',
'#data_type' => 'string', // I want serialized array
'#weight' => 0,
'#update_all' => FALSE, // Missing $form_state['values']['batch_all_setting'];
'#module' => t('Domain Configuration'),
);
return $batch;
}
function service_links_service_links_show_form() {
$form = array('#title' => t('Service Links Show'), '#type' => 'fieldset');
$services = service_links_get_links(NULL, TRUE);
$settings['show'] = variable_get('service_links_show', NULL);
$settings['weight'] = variable_get('service_links_weight', NULL);
foreach ($services as $service_id => $service) {
$icon = isset($service['icon']) ? service_links_expand_path($service['icon'], 'preset') : service_links_expand_path("$service_id.png", 'preset');
$weight = isset($settings['weight'][$service_id]) ? $settings['weight'][$service_id] : 0;
//
$form[$service_id] = array(
'#service' => ucwords(str_replace('_', ' ', $service['module'])),
'#weight' => $weight,
'#type' => 'checkbox',
'#title' => theme('image', array('path' => $icon)) . " " . t('%name link', array('%name' => $service['name'])),
'#return_value' => 1,
'#default_value' => isset($settings['show'][$service_id]) ? $settings['show'][$service_id] : 0,
);
}
return $form;
}
The values saved properly into the domain_conf table, because domain_conf serialize the values the same way service_links module does. But the domain_batch_form does not display the saved values properly, without the following patch. The domain_batch_form assumes your dealing with a single element. I am dealing with a fieldset with a bunch of serveral checkbox and not a single form element. The default values in may case is an array, and I must set the default value for each checkbox form element.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 1813502-admin.patch | 1016 bytes | agentrickard |
| #2 | domain_admin-default_value-1813502-2.patch | 1.01 KB | Bill Choy |
| domain_batch_form_fieldset.patch | 980 bytes | Bill Choy |
Comments
Comment #1
Bill Choy commentedHay...how do I set the patch to "NEEDS REVIEW"??
Comment #2
Bill Choy commentedHere is proposed patch.
Comment #2.0
Bill Choy commentedUpdated issue summary.
Comment #3
agentrickardInteresting edge case.
Comment #4
agentrickardSeems harmless. Committing.
Comment #5.0
(not verified) commentedUpdated issue summary.