1 views_handler_field_bulk_form.inc views_handler_field_bulk_form::views_form(&$form, &$form_state)

Form constructor for the bulk form.

Parameters

array $form: An associative array containing the structure of the form.

array $form_state: An associative array containing the current state of the form.

File

core/modules/views/handlers/views_handler_field_bulk_form.inc, line 94
Definition of views_handler_field_bulk_form.

Class

views_handler_field_bulk_form
Defines a actions-based bulk operation form element.

Code

function views_form(&$form, &$form_state) {
  // Add the tableselect javascript.
  $form['#attached']['js'][] = 'core/misc/tableselect.js';

  // Render checkboxes for all rows.
  $form[$this->options['id']]['#tree'] = TRUE;
  foreach ($this->view->result as $row_index => $row) {
    $form[$this->options['id']][$row_index] = array(
      '#type' => 'checkbox',
      // We are not able to determine a main "title" for each row, so we can
      // only output a generic label.
      '#title' => t('Update this item'),
      '#title_display' => 'invisible',
      '#return_value' => $row->{$this->field_alias},
      '#default_value' => !empty($form_state['values'][$this->options['id']][$row_index]) ? 1 : NULL,
      '#attributes' => array('data-tableselect-id' => $this->options['id'])
    );
  }

  // Ensure a consistent container for filters/operations in the view header.
  $form['header'] = array(
    '#weight' => -100,
  );

  // Build the bulk operations action widget for the header.
  // Allow themes to apply .container-inline on this separate container.
  $form['header'][$this->options['id']] = array(
    '#type' => 'container',
    '#attributes' => array('class' => array('views-bulk-form')),
  );
  $form['header'][$this->options['id']]['action'] = array(
    '#title' => t('Action'),
    '#title_display' => 'none',
    '#type' => 'select',
    '#options' => $this->get_bulk_options(),
    '#empty_option' => '- ' . t('Choose an action') . ' -',
    '#required' => TRUE,
  );

  // Set the form actions container in the header.
  $actions['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Execute'),
  );
  $form['header'][$this->options['id']]['actions'] = $actions;
}