You are here

function views_send_form_alter in Views Send 7

Same name and namespace in other branches
  1. 6 views_send.module \views_send_form_alter()

Implements hook_form_alter().

File

./views_send.module, line 140
The Views Send module.

Code

function views_send_form_alter(&$form, &$form_state, $form_id) {
  if (strpos($form_id, 'views_form_') === 0) {
    $field = _views_send_get_field_selector($form_state['build_info']['args'][0]);
  }

  // This form isn't used by Views Send.
  if (empty($field)) {
    return;
  }

  // Allow Views Send to work when embedded using views_embed_view(), or in a block.
  if (empty($field->view->override_path)) {
    if (!empty($field->view->preview) || $field->view->display_handler instanceof views_plugin_display_block) {
      $field->view->override_path = $_GET['q'];
    }
  }
  $query = drupal_get_query_parameters($_GET, array(
    'q',
  ));
  $form['#action'] = url($field->view
    ->get_url(), array(
    'query' => $query,
  ));

  // Cache the built form to prevent it from being rebuilt prior to validation
  // and submission, which could lead to data being processed incorrectly,
  // because the views rows (and thus, the form elements as well) have changed
  // in the meantime. Matching views issue: http://drupal.org/node/1473276.
  $form_state['cache'] = TRUE;

  // Add the custom CSS for all steps of the form.
  $form['#attached']['css'][] = drupal_get_path('module', 'views_send') . '/views_send.css';
  if ($form_state['step'] == 'views_form_views_form') {
    $form['actions']['submit']['#value'] = t('Send e-mail');
    $form['actions']['submit']['#submit'] = array(
      'views_send_form_submit',
    );
    if (isset($form['#prefix']) && $form['#prefix'] == '<div class="vbo-views-form">') {
      $form['#prefix'] = '<div class="vbo-views-form views-send-selection-form">';
    }
    else {
      $form['#prefix'] = '<div class="views-send-selection-form">';
    }
    $form['#suffix'] = '</div>';

    // Add the custom JS for this step of the form.
    $form['#attached']['js'][] = drupal_get_path('module', 'views_send') . '/views_send.js';

    // Adds the "select all" functionality for non-table style plugins
    // if the view has results.
    if (!empty($field->view->result) && !$field->view->style_plugin instanceof views_plugin_style_table) {
      $form['select_all_markup'] = array(
        '#type' => 'markup',
        '#markup' => theme('views_send_select_all'),
      );
    }
  }
}