You are here

function domain_conf_form in Domain Access 6.2

Same name and namespace in other branches
  1. 7.3 domain_conf/domain_conf.admin.inc \domain_conf_form()
  2. 7.2 domain_conf/domain_conf.admin.inc \domain_conf_form()

Custom form to generate domain-specific site settings.

The items on this form are taken from hook_domainbatch() and hook_domainconf(). See the API for more information.

Parameters

$domain: The domain currently being updated.

1 string reference to 'domain_conf_form'
domain_conf_page in domain_conf/domain_conf.admin.inc
The domain conf page callback router.

File

domain_conf/domain_conf.admin.inc, line 43
Domain manager configuration options.

Code

function domain_conf_form($form_state, $domain) {
  $form = array();
  $batch = module_invoke_all('domainbatch');
  $settings = array();
  $data = db_result(db_query("SELECT settings FROM {domain_conf} WHERE domain_id = %d", $domain['domain_id']));
  if (!empty($data)) {
    $settings = domain_unserialize($data);
  }
  $default_group = t('Site configuration');
  foreach ($batch as $key => $action) {
    $permission = isset($action['#permission']) ? $action['#permission'] : 'administer domains';
    if (!user_access($permission) || $action['#domain_action'] != 'domain_conf') {
      continue;
    }
    if ($action['#form']['#type'] == 'select') {
      $action['#form']['#options'] = array(
        'domain-conf-ignore' => t('Use primary domain settings'),
      ) + $action['#form']['#options'];
    }
    $group = isset($action['#group']) ? $action['#group'] : $default_group;
    if (!isset($form[$group])) {
      $form[$group] = array(
        '#type' => 'fieldset',
        '#title' => $group,
        '#collapsible' => TRUE,
      );
    }
    $form[$group][$key] = $action['#form'];
    $form[$group][$key]['#default_value'] = isset($settings[$key]) ? $settings[$key] : $action['#system_default'];

    // Change the path for the frontpage.
    if ($key == 'site_frontpage') {
      global $base_url;
      $prefix = $base_url . '/';
      $_path = parse_url($prefix);
      $str = $_path['host'];
      $fix = preg_replace("/{$str}/", $domain['subdomain'], $prefix, 1);
      $form[$default_group]['site_frontpage']['#field_prefix'] = $fix;
    }
  }
  $form['domain_id'] = array(
    '#type' => 'value',
    '#value' => $domain['domain_id'],
  );

  // Site name must be edited at the domain creation screen.
  if (isset($form[$default_group]['site_name'])) {
    $form[$default_group]['site_name'] = array(
      '#disabled' => TRUE,
      '#title' => t('Site name'),
      '#description' => t('The name of this web site, as entered in the <a href="!url">domain-specific settings</a>.', array(
        '!url' => url('admin/build/domain/edit/' . $domain['domain_id']),
      )),
      '#type' => 'textfield',
      '#default_value' => $domain['sitename'],
      '#weight' => -100,
    );
  }

  // Locale module is a little tricky, so handle it properly.
  $str = t('Language settings');
  if (isset($form[$str]['language_default']) && !isset($settings['language_default'])) {
    $form[$str]['language_default']['#default_value'] = NULL;
  }

  // Grab any extra elements defined by other modules.
  $extra = domain_conf_api(TRUE, $settings);

  // Merge the $extra and $form arrays.
  $form = array_merge($form, $extra);
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save domain settings'),
    '#weight' => 10,
  );
  return $form;
}