You are here

function forward_form in Forward 7.3

Same name and namespace in other branches
  1. 5 forward.module \forward_form()
  2. 6 forward.module \forward_form()
  3. 7 forward.module \forward_form()
  4. 7.2 forward.module \forward_form()

Callback function for the forward form

7 string references to 'forward_form'
forward_block_view in ./forward.module
Implements hook_block_view().
forward_entity_view in ./forward.module
Implements hook_entity_view().
forward_form_alter in ./forward.module
Implements hook_form_alter().
forward_menu in ./forward.module
Implements hook_menu().
forward_mollom_form_info in ./forward.module
Implements hook_mollom_form_info().

... See full list

File

./forward.module, line 404
Allows forwarding of entities by email, and provides a record of how often each has been forwarded.

Code

function forward_form($form, &$form_state, $path = NULL, $entity_wrapper = NULL, $inline = FALSE) {
  global $base_url, $user, $language;
  $emailtype = $path == 'epostcard' ? $path : 'email';

  // Retrieve entity parts
  if ($entity_wrapper) {
    $entity_type = $entity_wrapper
      ->type();
    $entity = $entity_wrapper
      ->value();
  }
  else {
    $entity_type = NULL;
    $entity = NULL;
  }

  // Setup entity path
  if (!$path && $entity_wrapper) {
    $uri = entity_uri($entity_type, $entity);
    $path = drupal_get_path_alias($uri['path'], entity_language($entity_type, $entity));
  }
  elseif ($path) {
    $path = drupal_get_path_alias($path, $language->language);
  }

  // Setup token
  $token = _forward_get_token($path, $entity_wrapper);

  // Place form fields in a fieldset when displaying inline
  if ($inline) {
    $fieldset_title = token_replace(check_plain(t(variable_get('forward_link_title', 'Email this [forward:entity-type]'))), $token);
    $form['message'] = array(
      '#type' => 'fieldset',
      '#title' => $fieldset_title,
      '#description' => '',
      '#collapsed' => TRUE,
      '#collapsible' => TRUE,
      '#weight' => 10,
    );
  }
  $form['message']['instructions'] = array(
    '#type' => 'item',
    '#markup' => filter_xss_admin(token_replace(t(variable_get('forward_instructions', '<p>Thank you for your interest in spreading the word about [site:name].</p><p>NOTE: We only request your email address so that the person you are recommending the page to knows that you wanted them to see it, and that it is not junk mail. We do not capture any email address.</p>')), $token)),
  );
  $form['message']['email'] = array(
    '#type' => 'textfield',
    '#title' => t('Your Email'),
    '#size' => 58,
    '#maxlength' => 256,
    '#required' => TRUE,
  );
  $form['message']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Your Name'),
    '#size' => 58,
    '#maxlength' => 256,
    '#required' => TRUE,
  );
  $form['message']['recipients'] = array(
    '#type' => 'textarea',
    '#title' => t('Send To'),
    '#cols' => 50,
    '#rows' => 5,
    '#description' => t('Enter multiple addresses on separate lines or separate them with commas.'),
    '#required' => TRUE,
  );

  // Indicate which page is being forwarded unless the form is on the same page as the entity being forwarded
  if ($emailtype == 'email' && !$inline) {
    $label = $entity_type && $entity ? entity_label($entity_type, $entity) : $path;
    $form['message']['page'] = array(
      '#type' => 'item',
      '#title' => t('You are going to email the following'),
      '#markup' => l($label, $path),
    );
  }
  $form['message']['subject'] = array(
    '#type' => 'item',
    '#title' => t('Message Subject'),
    '#markup' => token_replace(t(variable_get('forward_' . $emailtype . '_subject', '[forward:sender] has sent you a message from [site:name]')), $token),
  );
  $form['message']['body'] = array(
    '#type' => 'item',
    '#title' => t('Message Body'),
    '#markup' => token_replace(t(variable_get('forward_' . $emailtype . '_message', '[forward:sender] thought you would like to see the [site:name] web site.')), $token),
  );
  if (variable_get('forward_message', TRUE)) {
    $form['message']['message'] = array(
      '#type' => 'textarea',
      '#title' => t('Your Personal Message'),
      '#default_value' => '',
      '#cols' => 50,
      '#rows' => 5,
      '#description' => '',
      '#required' => variable_get('forward_message', 1) == 2 ? TRUE : FALSE,
    );
  }
  $form['message']['path'] = array(
    '#type' => 'hidden',
    '#value' => $path,
  );
  $form['message']['entity_type'] = array(
    '#type' => 'hidden',
    '#value' => $entity_type,
  );
  if ($entity_wrapper) {
    list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
  }
  $form['message']['entity_id'] = array(
    '#type' => 'hidden',
    '#value' => $entity_wrapper ? $id : 0,
  );
  $form['message']['forward_footer'] = array(
    '#type' => 'hidden',
    '#value' => variable_get('forward_footer', ''),
  );
  if ($inline) {

    // When using a collapsible form, move submit button into fieldset
    $form['message']['actions'] = array(
      '#type' => 'actions',
    );
    $form['message']['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Send Message'),
    );
  }
  else {

    // When using a separate form page, use actions directly so Mollom knows where to place its content
    $form['actions'] = array(
      '#type' => 'actions',
    );
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Send Message'),
    );
  }

  // Default name and email address to logged in user
  if (!user_is_anonymous()) {
    if (user_access('override email address')) {
      $form['message']['email']['#default_value'] = $user->mail;
    }
    else {

      // User not allowed to change sender email address
      $form['message']['email']['#type'] = 'hidden';
      $form['message']['email']['#value'] = $user->mail;
    }
    $form['message']['name']['#default_value'] = $user->name;
  }
  return $form;
}