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.

Comments

Bill Choy’s picture

Hay...how do I set the patch to "NEEDS REVIEW"??

Bill Choy’s picture

StatusFileSize
new1.01 KB

Here is proposed patch.

Bill Choy’s picture

Issue summary: View changes

Updated issue summary.

agentrickard’s picture

Status: Active » Needs review

Interesting edge case.

agentrickard’s picture

Status: Needs review » Fixed
StatusFileSize
new1016 bytes

Seems harmless. Committing.

   ad02a77..81ecdd7  7.x-3.x -> 7.x-3.x

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.