domain_prefix_configure_form

Versions
domain
domain_prefix_configure_form()

FormsAPI for generating the configuration form

Code

domain_prefix/domain_prefix.admin.inc, line 54

<?php
function domain_prefix_configure_form() {
  // We must use the settings from the root domain.
  $default = domain_default();
  domain_set_domain($default['domain_id'], TRUE);

  // Get the tables for the root installation.
  $tables = domain_prefix_get_tables();

  // Remove the disallowed tables.
  $disallow = domain_prefix_disallow();
  // Get the current settings.
  $info = variable_get('domain_prefix', NULL);
  $settings = $info['settings'];
  $source_defaults = $info['sources'];

  $form = array();
  $form['domain'] = array(
    '#type' => 'fieldset',
    '#title' => t('Domain creation rules'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE
  );
  $form['domain']['domain_prefix_options'] = array(
    '#type' => 'radios',
    '#title' => t('Domain creation options'),
    '#description' => t('Determines what actions to take when creating new domain records.'),
    '#options' => array(1 => t('Generate tables as defined below'), 0 => t('Do not generate any tables')),
    '#default_value' => variable_get('domain_prefix_options', 1),
    '#required' => TRUE
  );
  $last = ''; // Flag for module grouping.
  // Get the source table data.
  $root = domain_default();
  foreach ($tables as $table => $info) {
    if (!in_array($table, $disallow) && substr($table, 0, 7) != 'domain_') {
      if (empty($settings[$table])) {
        $settings[$table] = DOMAIN_PREFIX_IGNORE;
        $source_defaults['_source_'. $table] = 0;
      }
      $module = domain_prefix_get_name($info);
      if ($last != $module) {
        $last = $module;
      }
      else {
        $module = '';
      }
      $options = array();
      $options[DOMAIN_PREFIX_IGNORE] = t('ignore');
      $options[DOMAIN_PREFIX_CREATE] = t('create');
      $options[DOMAIN_PREFIX_COPY] = t('copy');
      $form['domain_prefix'][$table] = array(
        '#type' => 'radios',
        '#title' => $table,
        '#options' => $options,
        '#default_value' => $settings[$table],
        '#description' => $module
      );
      // Get the table copying options for this entry.
      // Can't pass a zero through FormAPI select.
      $sources = array();
      $sources[0] = $root['sitename'];
      // Check to see if other table prefixes have been created.
      $result = db_query("SELECT dp.domain_id, d.sitename FROM {domain_prefix} dp
        INNER JOIN {domain} d ON dp.domain_id = d.domain_id
        WHERE dp.tablename = '%s' AND dp.status > %d", $table, 1);
      while ($data = db_fetch_array($result)) {
        $sources[$data['domain_id']] = $data['sitename'];
      }

      $form['domain_source']['_source_'. $table] = array(
        '#type' => 'select',
        '#title' => '',
        '#options' => $sources,
        '#default_value' => $source_defaults['_source_'. $table],
      );
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save prefix settings'),
  );
  $form['restore'] = array(
    '#type' => 'submit',
    '#value' => t('Restore defaults'),
  );
  return $form;
}
?>

Contact

  • agentrickard [at] gmail [dot] com

Donations

My Amazon.com Wish List