You are here

hosting_signup.module in Hostmaster (Aegir) 6

Provides a signup form that can be run on remote sites

File

modules/hosting/signup/hosting_signup.module
View source
<?php

/**
 * @file Provides a signup form that can be run on remote sites
 */

/**
 * Implementation of hook_menu
 */
function hosting_signup_menu() {
  $items['hosting/signup'] = array(
    'title' => 'Sign up for a site',
    'description' => 'Create your own hosted site',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'hosting_signup_form',
    ),
    'access arguments' => array(
      'access hosting signup form',
    ),
  );
  $items['hosting/signup/thanks'] = array(
    'page callback' => 'hosting_signup_thanks',
    'type' => MENU_CALLBACK,
    'access arguments' => array(
      'access hosting signup form',
    ),
  );
  return $items;
}

/**
 * Implementation of hook_perm
 */
function hosting_signup_perm() {
  return array(
    'access hosting signup form',
  );
}

/**
 * Thank you page callback
 */
function hosting_signup_thanks($url = '', $email = '', $name = '') {
  return t("<h3>Thank you @name</h3>\n    Your site (@url) has been requested, and the moment it is ready you will receive a mail at @email\n with instructions on how to log into it.", array(
    "@name" => $name,
    "@url" => $url,
    "@email" => $email,
  ));
}

/**
 * Form definition
 *
 * This is a mixture of the client form and node form, 
 * and in the future we will be able to configure which
 * forms we want to be present.
 */
function hosting_signup_form() {
  global $user;
  if (!variable_get('hosting_client_register_user', FALSE) && !$user->uid) {
    drupal_set_message(t("Please login first. We have no way of guessing your email and this site is configured not to register new users. You will not receive the login link for your new site. This is probably a bad configuration."));
  }
  $node = new stdClass();
  $form['site'] = hosting_site_form($node);
  unset($form['site']['client']);
  $state = array();
  foreach (module_implements('form_alter') as $module) {
    $function = $module . '_form_alter';
    $function($form['site'], $state, 'site_node_form');
  }
  unset($form['site']['info']['client']);
  $form['client'] = hosting_client_form($node);
  foreach (module_implements('form_alter') as $module) {
    $function = $module . '_form_alter';
    $function($form['client'], $state, 'client_node_form');
  }
  $form['client']['client_name'] = $form['client']['title'];
  if (variable_get('hosting_client_register_user', FALSE) && !$user->uid) {
    $form['client']['email']['#required'] = TRUE;
    $form['client']['email_confirm']['#required'] = TRUE;
  }
  unset($form['client']['title']);
  $form['new_client'] = array(
    '#type' => 'value',
    '#value' => TRUE,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t("Sign up"),
  );
  return $form;
}

/**
 * Form validation
 *
 * This is the validation that the form does.
 */
function hosting_signup_form_validate($form, &$form_state) {
  $client = (object) $form_state['values'];
  $client->type = 'client';
  $client->title = $client->client_name;
  node_validate($client);
  $site = (object) $form_state['values'];
  $site->type = 'site';
  node_validate($site);
}

/**
 * Form submission
 *
 * Generates the nodes and saves them.
 */
function hosting_signup_form_submit($form, &$form_state) {
  $client = (object) $form_state['values'];
  $client->type = 'client';
  $client->status = 1;
  $client->title = $client->client_name;
  node_save($client, 'submit');
  $site = (object) $form_state['values'];
  $site->type = 'site';
  $site->status = 1;
  $site->client = $client->nid;
  $site->uid = $client->uid;
  node_save($site);
  $form_state['redirect'] = sprintf("hosting/signup/thanks/%s/%s/%s", $site->title, $client->email, $client->client_name);
}

Functions

Namesort descending Description
hosting_signup_form Form definition
hosting_signup_form_submit Form submission
hosting_signup_form_validate Form validation
hosting_signup_menu Implementation of hook_menu
hosting_signup_perm Implementation of hook_perm
hosting_signup_thanks Thank you page callback