You are here

function domain_form in Domain Access 7.3

Same name and namespace in other branches
  1. 6.2 domain.admin.inc \domain_form()
  2. 7.2 domain.admin.inc \domain_form()

FormsAPI for editing a domain record

Parameters

$form: The current form, passed by FormsAPI.

$form_state: The current form state, passed by FormsAPI.

$domain: An array containing the record from the {domain} table.

$arguments: An array of additional hidden key/value pairs to pass to the form. Used by child modules to control behaviors. Currently supported arguments are: 'user_submitted' => TRUE Indicates that a form should not process administrative messages and paths upon form submit. Used by the Domain User module.

1 string reference to 'domain_form'
domain_menu in ./domain.module
Implements hook_menu().

File

./domain.admin.inc, line 418
Administration functions for the domain module.

Code

function domain_form($form, &$form_state, $domain = array(), $arguments = array()) {
  $_domain = domain_get_domain();

  // This action should be performed from the primary domain unless overridden.
  $error = FALSE;
  if (!isset($arguments['ignore_domain_status_check'])) {
    if (variable_get('domain_edit_on_primary', 1)) {
      domain_check_primary();
    }
    if (!empty($domain)) {
      $error = domain_check_response($domain);
      if ($error && empty($_POST)) {
        drupal_set_message($error, 'warning', FALSE);
      }
    }
  }

  // Ensure indexes are set.
  foreach ($_domain as $key => $value) {
    if (!isset($domain[$key])) {
      $domain[$key] = NULL;
    }
  }
  $form = array();
  drupal_set_title(t('Edit !domain', array(
    '!domain' => $domain['subdomain'],
  )));
  $form['#domain'] = $domain;

  // The $arguments array allows other modules to pass values to change the behavior
  // of submit and validate functions.
  if (!empty($arguments)) {
    $form['domain_arguments'] = array(
      '#type' => 'value',
      '#value' => $arguments,
    );
  }
  $form['domain_id'] = array(
    '#type' => 'value',
    '#value' => $domain['domain_id'],
  );
  if (!variable_get('domain_allow_non_ascii', FALSE)) {
    $description = t('Must contain only dots, lowercase alphanumeric characters, dashes and a colon (if using alternative ports).');
  }
  else {
    $description = t('Must contain only dots, lowercase alphanumeric and ASCII characters, dashes and a colon (if using alternative ports).');
  }
  $form['subdomain'] = array(
    '#type' => 'textfield',
    '#title' => t('Domain'),
    '#size' => 40,
    '#maxlength' => 80,
    '#required' => TRUE,
    '#default_value' => $domain['subdomain'],
    '#description' => t('The allowed domain, using the full <em>path.example.com</em> format.') . '<br />' . t('Leave off the http:// and the trailing slash and do not include any paths.') . '<br />' . $description,
  );
  $form['machine_name'] = array(
    '#type' => 'machine_name',
    '#machine_name' => array(
      'source' => array(
        'subdomain',
      ),
      'exists' => 'domain_check_machine_name',
    ),
    '#default_value' => $domain['machine_name'],
  );
  $form['sitename'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#size' => 40,
    '#maxlength' => 80,
    '#required' => TRUE,
    '#default_value' => $domain['sitename'],
    '#description' => t('The human-readable name of this domain.'),
  );
  $form['scheme'] = array(
    '#type' => 'radios',
    '#title' => t('Domain URL scheme'),
    '#required' => TRUE,
    '#options' => array(
      'http' => 'http://',
      'https' => 'https://',
    ),
    '#default_value' => !empty($domain['scheme']) ? $domain['scheme'] : 'http',
    '#description' => t('The URL scheme for accessing this domain.'),
  );
  $form['valid'] = array(
    '#type' => 'radios',
    '#title' => t('Domain status'),
    '#required' => TRUE,
    '#options' => array(
      1 => t('Active'),
      0 => t('Inactive'),
    ),
    '#default_value' => isset($domain['valid']) ? $domain['valid'] : 1,
    '#description' => t('Must be set to "Active" for users to navigate to this domain.'),
  );
  $next_weight = 0;
  foreach (domain_domains() as $record) {
    if ($record['weight'] > $next_weight) {
      $next_weight = $record['weight'];
    }
  }
  $form['weight'] = array(
    '#type' => 'weight',
    '#title' => t('Weight'),
    '#required' => TRUE,
    '#delta' => count(domain_domains()) + 1,
    '#default_value' => isset($domain['weight']) ? $domain['weight'] : $next_weight + 1,
    '#description' => t('The sort order for this record. Lower values display first.'),
  );
  $form['is_default'] = array(
    '#type' => 'checkbox',
    '#title' => t('Default domain'),
    '#default_value' => isset($domain['is_default']) ? $domain['is_default'] : 0,
    '#description' => t('If a URL request fails to match a domain record, the settings for this domain will be used.'),
  );

  // If the server did not respond properly, do not allow this record to be set
  // as the default domain.
  if ($error) {
    $form['is_default']['#description'] .= '<br />' . t('<strong>This domain did not respond correctly. It cannot be set as your primary domain unless you select <em>Ignore server response warning</em></strong>.');
    $form['ignore'] = array(
      '#type' => 'checkbox',
      '#title' => t('Ignore server response warning'),
      '#default_value' => 0,
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save domain record'),
    '#prefix' => '<br />',
  );
  $form['#validate'][] = 'domain_form_validate';
  $form['#redirect'] = array(
    'admin/structure/domain/view',
  );
  return $form;
}