You are here

function domain_conf_form_alter in Domain Access 5

Implement hook_form_alter()

Since this function is only loaded at the path admin/build/domain/conf, we don't have to worry about hook_form_alter() being called when not wanted.

File

domain_conf/domain_conf.module, line 132
Domain manager configuration options.

Code

function domain_conf_form_alter($form_id, &$form) {

  // We use the system_site_information_settings form as a base, and add the elements we need
  // from other forms.  The default values are altered based on stored settings.
  if ($form_id == 'system_site_information_settings') {

    // Check to be certain that we are on the right form page.
    $module = arg(2);
    $action = arg(3);
    if ($module == 'domain' && $action == 'conf') {
      $domain_id = arg(4);
      $domain = domain_lookup($domain_id);
      $data = db_result(db_query("SELECT settings FROM {domain_conf} WHERE domain_id = %d", $domain['domain_id']));
      if (!empty($data)) {
        $settings = unserialize($data);
      }
      else {
        $settings = array();
      }
      $unset = array(
        'buttons',
        '#submit',
      );
      foreach ($unset as $key) {
        unset($form[$key]);
      }
      $form['main'] = array(
        '#type' => 'fieldset',
        '#title' => t('Domain information'),
        '#collapsible' => TRUE,
        '#weight' => -10,
      );

      // Put the defaults in the fieldset
      $fields = array(
        'site_name',
        'site_mail',
        'site_slogan',
        'site_mission',
        'site_footer',
        'site_frontpage',
        'anonymous',
      );
      foreach ($fields as $field) {
        $form['main'][$field] = $form[$field];
        unset($form[$field]);
      }

      // Change the path for the frontpage.
      $prefix = $form['main']['site_frontpage']['#field_prefix'];
      $_path = parse_url($prefix);
      $str = $_path['host'];
      $fix = preg_replace("/{$str}/", $domain['subdomain'], $prefix, 1);
      $form['main']['site_frontpage']['#field_prefix'] = $fix;

      // Admin theme settings
      $themes = list_themes();
      ksort($themes);
      $options[] = t('Use domain default theme');
      foreach ($themes as $key => $value) {
        $options[$key] = $key;
      }
      $form['main']['admin_theme'] = array(
        '#type' => 'select',
        '#title' => t('Administrative theme'),
        '#options' => $options,
        '#default_value' => variable_get('admin_theme', '0'),
      );

      // Date settings: set the default timezone
      $form['date'] = array(
        '#type' => 'fieldset',
        '#title' => t('Timezone settings'),
        '#collapsible' => TRUE,
        '#weight' => -5,
      );
      $zones = _system_zonelist();
      $form['date']['date_default_timezone'] = array(
        '#type' => 'select',
        '#title' => t('Default time zone'),
        '#default_value' => isset($settings['date_default_timezone']) ? $settings['date_default_timezone'] : variable_get('date_default_timezone', 0),
        '#options' => $zones,
        '#description' => t('Select the default site time zone.'),
      );

      // Offline notices.
      $form['offline'] = array(
        '#type' => 'fieldset',
        '#title' => t('Maintenance settings'),
        '#collapsible' => TRUE,
        '#weight' => 5,
      );
      $form['offline']['site_offline'] = array(
        '#type' => 'radios',
        '#title' => t('Site status'),
        '#default_value' => isset($settings['site_offline']) ? $settings['site_offline'] : variable_get('site_offline', 0),
        '#options' => array(
          t('Online'),
          t('Off-line'),
        ),
        '#description' => t('When set to "Online", all visitors will be able to browse your site normally. When set to "Off-line", only users with the "administer site configuration" permission will be able to access your site to perform maintenance; all other visitors will see the site off-line message configured below. Authorized users can log in during "Off-line" mode directly via the <a href="@user-login">user login</a> page.', array(
          '@user-login' => url('user'),
        )),
      );
      $form['offline']['site_offline_message'] = array(
        '#type' => 'textarea',
        '#title' => t('Site off-line message'),
        '#default_value' => isset($settings['site_offline_message']) ? $settings['site_offline_message'] : variable_get('site_offline_message', t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array(
          '@site' => $domain['sitename'],
        ))),
        '#description' => t('Message to show visitors when the site is in off-line mode.'),
      );

      // Site name must be edited at the domain creation screen.
      $form['main']['site_name']['#disabled'] = TRUE;
      $form['main']['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']),
      ));

      // Reset the provided form defaults, if needed
      $form['main']['site_name']['#default_value'] = $domain['sitename'];
      $form['main']['site_mail']['#default_value'] = isset($settings['site_mail']) ? $settings['site_mail'] : variable_get('site_mail', ini_get('sendmail_from'));
      $form['main']['site_slogan']['#default_value'] = isset($settings['site_slogan']) ? $settings['site_slogan'] : variable_get('site_slogan', '');
      $form['main']['site_mission']['#default_value'] = isset($settings['site_mission']) ? $settings['site_mission'] : variable_get('site_mission', '');
      $form['main']['site_footer']['#default_value'] = isset($settings['site_footer']) ? $settings['site_footer'] : variable_get('site_footer', '');
      $form['main']['site_frontpage']['#default_value'] = isset($settings['site_frontpage']) ? $settings['site_frontpage'] : variable_get('site_frontpage', 'node');
      $form['main']['anonymous']['#default_value'] = isset($settings['anonymous']) ? $settings['anonymous'] : variable_get('anonymous', t('Guest'));

      // Domain information, for saving.
      $form['domain_id'] = array(
        '#type' => 'value',
        '#value' => $domain['domain_id'],
      );

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

      // Merge the $extra and $form arrays.
      $form = array_merge($form, $extra);

      // Submit functions
      $form['#submit']['domain_conf_form_submit'] = array();
      $form['#validate']['domain_conf_form_validate'] = array();
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Save domain settings'),
        '#weight' => 10,
      );
    }
  }
}