You are here

function hosting_platform_form in Hosting 7.4

Same name and namespace in other branches
  1. 5 platform/hosting_platform.module \hosting_platform_form()
  2. 6.2 platform/hosting_platform.module \hosting_platform_form()
  3. 7.3 platform/hosting_platform.module \hosting_platform_form()

Implements hook_form().

File

platform/hosting_platform.module, line 359
Platform node type definition.

Code

function hosting_platform_form(&$node) {
  $type = node_type_get_type($node);
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#required' => TRUE,
    '#description' => t('Choose a unique descriptive name for your platform. You very likely want this to be something like "Drupal 7.21".'),
    '#size' => 40,
    '#default_value' => $node->title,
    '#maxlength' => 255,
  );

  // Allow editing the "publish path" so that users can change their platforms if they need to.
  //  $base_path = variable_get('hosting_platform_base_path', '/var/aegir/platforms/');
  //  $default_path = '';
  //  $field_prefix = $base_path;
  //  if (isset($node->publish_path)) {
  //    // Strip the $base_path, since we prepend it in a validation handler.
  //    // This enforces platform publishing under the defined base path, even if
  //    // an error allows the path to be edited again.
  //    if (strpos($node->publish_path, $base_path) === 0) {
  //      $default_path = substr($node->publish_path, strlen($base_path));
  //    }
  //    else {
  //      // If publish path is not inside /var/aegir/platforms, use that as the default path and remove the field prefix.
  //      $default_path = $node->publish_path;
  //      $field_prefix = '';
  //    }
  //  }
  $form['git'] = array(
    '#type' => 'fieldset',
    '#title' => t('Git Information'),
    '#collapsible' => false,
    '#description' => $node->nid ? t('Change the git configuration of the codebase checked out to &path.', array(
      '&path' => $node->git_root,
    )) : t('Create this platform using a git repository.'),
    '#weight' => -1,
  );
  $form['git']['git_remote'] = array(
    '#type' => 'textfield',
    '#title' => t('Git Repository URL'),
    '#description' => t('The URL or path of the git repository to clone for this site.'),
    '#default_value' => $node->git_remote,
    '#required' => TRUE,
  );

  // @TODO: Detect clone state instead of just saying "it worked!".
  $git_root_description = $node->nid ? '<div class="alert alert-info"><i class="fa fa-info-circle"></i> ' . t('The repository was cloned to: &path', array(
    '&path' => $node->git_root,
  )) : t('The full path on the server to clone the git repository to.') . "</div>";
  $form['git']['git_root'] = array(
    '#type' => $node->nid ? 'value' : 'textfield',
    '#title' => t('Path to Clone'),
    '#default_value' => $node->git_root,
    '#weight' => 10,
    '#description' => $git_root_description,
    '#suffix' => $git_root_description,
  );
  $form['git']['git_reference'] = array(
    '#type' => 'textfield',
    '#title' => t('Git Reference'),
    '#description' => $node->nid ? t('Enter a git reference to checkout. If left blank, no changes will be made.') : t('The desired git reference. Can be a branch, tag or SHA. If left blank, the default branch will be checked out.'),
    '#default_value' => $node->git_reference,
  );
  $form['git']['git_docroot'] = array(
    '#type' => 'textfield',
    '#title' => t('Relative Docroot'),
    '#description' => t('The relative path within the git repository to publish to the web.'),
    '#default_value' => $node->git_docroot,
  );
  $form['git']['git_reset'] = array(
    '#type' => 'checkbox',
    '#title' => t('Reset working copy changes.'),
    '#description' => t('If checked, any changes to the cloned git code will be reset and lost.'),
    '#default_value' => $node->git_reset,
  );

  // @TODO: Decide to remove makefile support?
  //  $form['frommakefile'] = array(
  //    '#type' => 'fieldset',
  //    '#tree' => TRUE,
  //    '#title' => t('Deploy from makefile'),
  //    '#collapsible' => TRUE,
  //    '#description' => t('You may deploy this platform from a makefile.'),
  //    '#weight' => -1,
  //    '#access' =>
  //  );
  //
  //  $form['frommakefile']['makefile'] = array(
  //    '#type' => 'textfield',
  //    '#title' => t('Makefile'),
  //    '#description' => t('The absolute path on the filesystem or public URL of a makefile that will be used to create the platform in the directory specified above. If the directory already exists, this file will be ignored.'),
  //    '#size' => 40,
  //    '#default_value' => isset($node->makefile) ? $node->makefile : NULL,
  //    '#maxlength' => 255,
  //  );
  //
  //  $form['frommakefile']['make_working_copy'] = array(
  //    '#type' => 'radios',
  //    '#title' => t('Drush make option'),
  //    '#default_value' => isset($node->make_working_copy) ? $node->make_working_copy : 0,
  //    '#options' => array(
  //      0 => t('Normal - Discards SCM files'),
  //      1 => t('Working copy - preserves SCM files'),
  //    ),
  //  );
  $form['#after_build'][] = 'hosting_platform_form_platform_after_build';
  $servers = hosting_get_servers('http');
  if (count($servers) > 1) {
    $form['web_server'] = array(
      '#type' => 'radios',
      '#title' => t('Web server'),
      '#description' => t('The web server the sites will be hosted on.'),
      '#options' => $servers,
      '#default_value' => isset($node->web_server) ? $node->web_server : HOSTING_DEFAULT_WEB_SERVER,
    );
  }
  else {
    reset($servers);
    $form['web_server'] = array(
      '#type' => 'hidden',
      '#value' => key($servers),
    );
  }
  foreach (array(
    'verified',
    'platform_status',
  ) as $extra_attribute) {
    $form["{$extra_attribute}"] = array(
      '#type' => 'value',
      '#value' => isset($node->{$extra_attribute}) ? $node->{$extra_attribute} : NULL,
    );
  }
  return $form;
}