You are here

function hosting_site_form in Hosting 7.3

Same name and namespace in other branches
  1. 5 site/hosting_site.module \hosting_site_form()
  2. 6.2 site/hosting_site.form.inc \hosting_site_form()
  3. 7.4 site/hosting_site.form.inc \hosting_site_form()

Implements hook_form().

1 call to hosting_site_form()
hosting_signup_form in signup/hosting_signup.module
Form definition

File

site/hosting_site.form.inc, line 199
Site node form.

Code

function hosting_site_form($node, &$form_state) {
  $form['#node'] = $node;
  if (isset($node->nid)) {
    $form['info'] = array(
      '#prefix' => '<div class="clear-block" id="hosting-site-edit-info">',
      '#suffix' => '<br /></div>',
      '#weight' => -10,
    );
  }
  _hosting_site_field($form, $node, 'title', array(
    '#type' => 'textfield',
    '#title' => t('Domain name'),
    '#required' => TRUE,
    '#default_value' => isset($node->title) ? hosting_site_get_domain($node->title) : '',
    '#weight' => -10,
  ));

  // Install profiles.
  $profiles = hosting_get_profiles();
  foreach ($profiles as $id => $name) {
    $profile = hosting_package_instance_load(array(
      'p.nid' => $id,
    ));
    $profiles[$id] = theme('hosting_site_profile', array(
      'profile' => $profile,
      'html' => TRUE,
    ));
  }
  natcasesort($profiles);
  reset($profiles);
  _hosting_site_field($form, $node, 'profile', array(
    '#type' => 'radios',
    '#title' => t('Install profile'),
    '#description' => t('The type of site to install.<br />
                           The profile selected here determines the list of supported platforms below.'),
    '#options' => $profiles,
    '#default_value' => isset($node->profile) ? $node->profile : hosting_get_default_profile(key($profiles)),
    '#required' => TRUE,
    '#attributes' => array(
      'class' => array(
        "hosting-site-form-profile-options",
      ),
    ),
    '#ajax' => array(
      'callback' => 'hosting_site_platform_callback',
      'wrapper' => 'hosting-site-field-platform',
      'effect' => 'fade',
      'event' => 'change',
      'method' => 'replace',
    ),
  ), '_hosting_node_link');

  // Override the defaults if the profile has been changed.
  if (isset($form_state['values']['profile'])) {
    $selected_profile = $form_state['values']['profile'];
  }
  else {
    $selected_profile = hosting_package_instance_load(array(
      'p.nid' => hosting_get_default_profile(),
    ))->nid;
  }

  // Load platforms for the selected profile.
  $platforms = hosting_get_profile_platforms($selected_profile);
  $q = drupal_get_query_parameters();
  if (isset($q['platform']) && is_numeric($q['platform'])) {
    $default_platform = $q['platform'];

    // Since platform is predetermined, limit the options based on the selected platform.
    $selected_profile = hosting_package_instance_load(array(
      'platform' => $default_platform,
      'package_type' => 'profile',
    ))->nid;
    $platforms = hosting_get_profile_platforms($selected_profile);
    $form['profile']['#default_value'] = $selected_profile;
    $form['profile']['#options'] = hosting_get_profiles($default_platform);
    foreach ($form['profile']['#options'] as $id => &$name) {
      $profile = hosting_package_instance_load(array(
        'p.nid' => $id,
      ));
      $name = theme('hosting_site_profile', array(
        'profile' => $profile,
        'html' => TRUE,
      ));
    }
    natcasesort($form['profile']['#options']);
    reset($form['profile']['#options']);

    // Set page title.
    drupal_set_title(t('Create site on platform @name', array(
      '@name' => $platforms[$default_platform],
    )));
  }
  else {
    $default_platform = NULL;
  }
  if (!array_key_exists($default_platform, $platforms)) {

    // Default to the first platform, if none was passed in the path.
    $default_platform = current(array_keys($platforms));
  }
  _hosting_site_field($form, $node, 'platform', array(
    '#type' => 'radios',
    '#title' => t('Platform'),
    '#required' => TRUE,
    '#description' => t('The platform you want the site to be hosted on.<br />
                          Not seeing a certain platform? Platforms shown are those that support the profile above.
                          If a different profile is selected, this list may change automatically.'),
    '#options' => $platforms,
    '#default_value' => isset($node->platform) ? $node->platform : $default_platform,
    '#ajax' => array(
      'callback' => 'hosting_site_language_callback',
      'wrapper' => 'hosting-site-field-site-language',
      'effect' => 'fade',
      'event' => 'change',
      'method' => 'replace',
    ),
  ), '_hosting_node_link');

  // Override the defaults if the profile has been changed.
  if (isset($form_state['values']['platform'])) {
    $selected_platform = $form_state['values']['platform'];
  }
  else {
    $selected_platform = NULL;
  }
  $languages = hosting_get_profile_languages($selected_profile, $selected_platform);
  _hosting_site_field($form, $node, 'site_language', array(
    '#type' => count($languages) > 10 ? 'select' : 'radios',
    '#title' => t('Language'),
    '#description' => t('The language of site being installed.'),
    '#options' => $languages,
    '#required' => TRUE,
    '#default_value' => isset($node->site_language) ? $node->site_language : 'en',
    '#attributes' => array(
      'class' => array(
        "hosting-site-form-site-language-options",
      ),
    ),
  ), '_hosting_language_name');
  _hosting_site_field($form, $node, 'db_server', array(
    '#type' => 'radios',
    '#title' => t('Database server'),
    '#required' => TRUE,
    '#description' => t('The database server the site will use to host its content.'),
    '#options' => hosting_get_servers('db'),
    '#default_value' => isset($node->db_server) ? $node->db_server : HOSTING_DEFAULT_DB_SERVER,
  ), '_hosting_node_link');
  foreach (array(
    'verified',
    'last_cron',
    'site_status',
  ) as $extra_attribute) {
    $form["{$extra_attribute}"] = array(
      '#type' => 'value',
      '#value' => isset($node->{$extra_attribute}) ? $node->{$extra_attribute} : NULL,
    );
  }
  return $form;
}