You are here

function domain_overview_form in Domain Access 7.3

Create an overview form for sorting domains and other quick actions.

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

File

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

Code

function domain_overview_form($form, &$form_state) {
  $check = (bool) db_query("SELECT COUNT(domain_id) FROM {domain}")
    ->fetchField();
  if (empty($check)) {
    domain_set_primary_domain();
  }

  // Check for the 7.x.3 update.
  domain_check_for_update();

  // Set the form.
  $default = domain_default();
  $active_domain = domain_get_domain();
  $form = array();
  $form['top'] = array(
    '#markup' => t('<p>The following domains have been created for your site.  The currently active domain <strong>is shown in boldface</strong>.  You
                    may click on a domain to change the currently active domain.  Your default domain is %name, which will be used for all requests that fail to resolve to a registered domain.</p>', array(
      '%name' => $default['subdomain'],
    )),
  );

  // Cannot use domain_domains() here because we need to sort the output.
  $domains = array();
  $header = array(
    array(
      'data' => t('Order'),
    ),
    array(
      'data' => t('Weight'),
    ),
    array(
      'data' => t('Name'),
    ),
    array(
      'data' => t('Domain'),
    ),
    array(
      'data' => t('Id'),
    ),
    array(
      'data' => t('Active'),
    ),
    array(
      'data' => t('Default'),
    ),
    array(
      'data' => t('Operations'),
    ),
  );

  // Set up the base query.
  $limit = variable_get('domain_list_size', DOMAIN_LIST_SIZE);
  $page = isset($_GET['page']) ? $_GET['page'] : 0;
  $query = db_select('domain', 'd')
    ->fields('d', array(
    'domain_id',
    'sitename',
    'subdomain',
    'scheme',
    'valid',
    'weight',
    'is_default',
  ))
    ->orderBy('weight')
    ->extend('PagerDefault')
    ->limit($limit);

  // Get the domains.
  $result = $query
    ->execute();
  while ($domain = $result
    ->fetchAssoc()) {
    $domains[$domain['domain_id']] = domain_api($domain);
  }
  if (empty($domains)) {
    $form['error'] = array(
      '#markup' => t('No domains have been configured. <a href="!url">Add a new domain</a>.', array(
        '!url' => url('admin/structure/domain/create'),
      )),
    );
    return $form;
  }

  // Get the count of all domains, which may be paginated.
  $delta = count(domain_domains());
  $form['domain']['#tree'] = TRUE;
  $form['header'] = array(
    '#type' => 'value',
    '#value' => $header,
  );
  $options = array();
  $i = -1;

  // Now build the form elements.
  foreach ($domains as $domain_id => $domain) {
    $options[$domain_id] = '';
    $form['domain'][$domain_id]['values'] = array(
      '#type' => 'value',
      '#value' => $domain,
    );
    $form['domain'][$domain_id]['weight'] = array(
      '#type' => 'weight',
      '#default_value' => $page * $limit + $i++,
      '#delta' => $delta,
      '#attributes' => array(
        'class' => array(
          'domain-weight',
        ),
      ),
    );
    $form['domain'][$domain_id]['sitename'] = array(
      '#type' => 'markup',
      '#markup' => $active_domain['domain_id'] == $domain_id ? '<strong>' . check_plain($domain['sitename']) . '</strong>' : check_plain($domain['sitename']),
    );
    $form['domain'][$domain_id]['subdomain'] = array(
      '#type' => 'markup',
      '#markup' => $active_domain['domain_id'] == $domain_id ? '<strong>' . l($domain['subdomain'], domain_get_uri($domain)) . '</strong>' : l($domain['subdomain'], domain_get_uri($domain)),
    );
    $form['domain'][$domain_id]['domain_id'] = array(
      '#type' => 'markup',
      '#markup' => check_plain($domain_id),
    );
    $form['domain'][$domain_id]['valid'] = array(
      '#type' => 'checkbox',
      // '#title' => !empty($domain['valid']) ? t('Active') : t('Inactive'),
      '#default_value' => !empty($domain['valid']),
    );
    $form['domain_actions'][$domain_id] = array(
      '#type' => 'markup',
      '#markup' => l(t('edit domain'), 'admin/structure/domain/view/' . $domain_id . '/edit'),
    );
  }
  $form['default_domain'] = array(
    '#type' => 'radios',
    '#options' => $options,
    '#default_value' => $default['domain_id'],
  );
  $form['pager'] = array(
    '#markup' => theme('pager'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}