domain_batch_form

Versions
domain
domain_batch_form($form_state, $action, $batch, $domains)

Generate the form data for a batch update.

Parameters

$form_state The current form state, passed by FormsAPI.

$action The name of the action to perform; corresponds to the keys of the $batch array returned by hook_domainbatch().

$batch The batch data for this $action, as defined by hook_domainbatch().

$domains The current settings for each domain.

Return value

A themed table of links and descriptions for batch actions.

Code

./domain.admin.inc, line 770

<?php
function domain_batch_form($form_state, $action, $batch, $domains) {
  $default = array();
  drupal_set_title($batch['#form']['#title']);

  $form = array();
  $form['message'] = array(
    '#type' => 'markup',
    '#value' => theme('domain_batch_title', $batch)
  );

  // For some values, allow every record to be updated.
  if (!empty($batch['#update_all'])) {
    $form['domain_batch_all'] = array(
      '#type' => 'fieldset',
      '#title' => t('Update value for all domains'),
      '#weight' => -10,
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#description' => t('By entering a value below and checking the <strong>Apply to all domains</strong> option, you can set the desired value for all domains.'),
    );
    $form['domain_batch_all']['batch_all_setting'] = $batch['#form'];
    $form['domain_batch_all']['batch_all_setting']['#default_value'] = $batch['#system_default'];
    $form['domain_batch_all']['batch_override'] = array(
      '#type' => 'checkbox',
      '#title' => t('Apply to all domains'),
    );
    $form['domain_batch_all']['submit'] = array('#type' => 'submit', '#value' => t('Update all domain settings'));
  }
  $form['domain_batch'] = array(
    '#tree' => TRUE,
    '#title' => $batch['#form']['#title'],
    '#description' => $batch['#meta_description']
  );

  foreach ($domains as $domain) {
    // Set the current value according to the stored values.
    if (isset($domain[$action])) {
      $default[$domain['domain_id']] = $domain[$action];
    }
    if ($batch['#domain_action'] == 'domain_conf') {
      // Set the default value to the main settings.
      // In rare cases, variable_get() returns unusable data, so we override it.
      if (empty($batch['#override_default'])) {
        $default[$domain['domain_id']] = variable_get($action, $batch['#system_default']);
      }
      else {
        $default[$domain['domain_id']] = $batch['#system_default'];
      }
      // Check for domain-specific settings.
      $result = db_result(db_query("SELECT settings FROM {domain_conf} WHERE domain_id = %d", $domain['domain_id']));
      $settings = domain_unserialize($result);
      if (isset($settings[$action])) {
        $default[$domain['domain_id']] = $settings[$action];
      }
    }
    else if ($batch['#domain_action'] == 'custom' && isset($batch['#lookup'])) {
      $default[$domain['domain_id']] = $batch['#system_default'];
      $func = $batch['#lookup'];
      $setting = $func($domain);
      if ($setting != -1) {
        $default[$domain['domain_id']] = $setting;
      }
    }
    // Take the settings from the $batch array.
    $form['domain_batch'][$domain['domain_id']] = $batch['#form'];
    // Add the domain-specific elements.
    $form['domain_batch'][$domain['domain_id']]['#sitename'] = $domain['sitename'];
    if (isset($default[$domain['domain_id']])) {
      $form['domain_batch'][$domain['domain_id']]['#default_value'] = $default[$domain['domain_id']];
    }
  }
  $api_keys = array('variable', 'table', 'data_type');
  // These are optional elements, only passed if present.
  foreach ($api_keys as $key) {
    if (isset($batch['#'. $key])) {
      $form[$key] = array('#type' => 'value', '#value' => $batch['#'. $key]);
    }
  }
  // Custom submit and validate handlers.
  foreach (array('submit', 'validate') as $key) {
    if (isset($batch['#'. $key])) {
      $form[$key .'_handler'] = array('#type' => 'value', '#value' => $batch['#'. $key]);
    }
  }
  $form['handler'] = array('#type' => 'value', '#value' => $batch['#domain_action']);
  $form['batch_item'] = array('#type' => 'value', '#value' => $action);
  $form['submit'] = array('#type' => 'submit', '#value' => t('Update domain settings'));

  return $form;
}
?>

Contact

  • agentrickard [at] gmail [dot] com

Donations

My Amazon.com Wish List