public function BulkFormBase::views_form

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.

1 call to BulkFormBase::views_form()
UserBulkForm::views_form in drupal/core/modules/user/lib/Drupal/user/Plugin/views/field/UserBulkForm.php
Provide a more useful title to improve the accessibility.
1 method overrides BulkFormBase::views_form()
UserBulkForm::views_form in drupal/core/modules/user/lib/Drupal/user/Plugin/views/field/UserBulkForm.php
Provide a more useful title to improve the accessibility.

File

drupal/core/modules/system/lib/Drupal/system/Plugin/views/field/BulkFormBase.php, line 83
Contains \Drupal\system\Plugin\views\field\BulkFormBase.

Class

BulkFormBase
Defines a generic bulk operation form element.

Namespace

Drupal\system\Plugin\views\field

Code

public function views_form(&$form, &$form_state) {

  // Add the tableselect javascript.
  $form['#attached']['library'][] = array(
    'system',
    'drupal.tableselect',
  );

  // Only add the bulk form options and buttons if there are results.
  if (!empty($this->view->result)) {

    // 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',
        '#default_value' => !empty($form_state['values'][$this->options['id']][$row_index]) ? 1 : NULL,
      );
    }

    // Replace the form submit button label.
    $form['actions']['submit']['#value'] = t('Apply');

    // Ensure a consistent container for filters/operations in the view header.
    $form['header'] = array(
      '#type' => 'container',
      '#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',
    );
    $form['header'][$this->options['id']]['action'] = array(
      '#type' => 'select',
      '#title' => t('With selection'),
      '#options' => $this
        ->getBulkOptions(),
    );

    // Duplicate the form actions into the action container in the header.
    $form['header'][$this->options['id']]['actions'] = $form['actions'];
  }
  else {

    // Remove the default actions build array.
    unset($form['actions']);
  }
}