| 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 100 - 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.
$bulk_options = $this->get_bulk_options();
if (!empty($bulk_options)) {
// 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' => $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;
// If the view has results, add the form element and markup to select all.
if (!empty($this->view->result)) {
$form['#attached']['js'][] = backdrop_get_path('module', 'views') . '/js/bulk_form.js';
// Set by JS to indicate that all rows on all pages are selected.
$form['select_all_pages'] = array(
'#type' => 'hidden',
'#attributes' => array('class' => 'views-select-all-pages--value'),
'#default_value' => FALSE,
);
$enable_select_all_pages = FALSE;
// If the view is paginated, and "select all items on all pages" is
// enabled, tell that to the theme function.
if ($this->options['enable_select_all_pages'] && isset($this->view->total_rows) && count($this->view->result) != $this->view->total_rows) {
$enable_select_all_pages = TRUE;
}
$form['select_all_pages_markup'] = array(
'#type' => 'markup',
'#markup' => theme('views_select_all_pages', array(
'view' => $this->view,
'enable_select_all_pages' => $enable_select_all_pages,
)),
);
}
}
}