| 1 views_handler_field_bulk_form.inc | views_handler_field_bulk_form::views_form_submit(&$form, &$form_state) |
Submit handler 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 183 - 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_submit(&$form, &$form_state) {
if ($form_state['step'] == 'views_form_views_form') {
$action_name = $form_state['values']['action'];
$action_info = actions_get_info($form_state['values']['action']);
$count = 0;
// If the flag to select all results in all pages is true, retrieve all
// entity IDs.
if ($form_state['values']['select_all_pages'] && ($this->view->query->pager->has_more_records() || $this->view->query->pager->get_current_page() > 0)) {
// We need to build a new view with the same parameters, but without a
// pager.
$new_view = views_get_view($this->view->name);
$new_view->set_exposed_input($this->view->get_exposed_input());
$new_view->set_arguments($this->view->args);
$new_view->set_display($this->view->current_display);
// Remove the pager to get all results.
$new_view->display_handler->set_option('pager', array(
'type' => 'none',
'options' => array(),
));
$new_view->build();
$new_view->execute($this->view->current_display);
$selected = array();
// Retrieve all entity IDs.
foreach ($new_view->result as $result) {
$selected[] = $result->{$this->real_field};
}
}
else {
// Filter only selected checkboxes.
$selected = array_filter($form_state['values'][$this->options['id']]);
}
if (!empty($selected)) {
$entity_type = $this->get_entity_type();
$entities = entity_load($entity_type, $selected);
$context = array();
foreach ($entities as $entity) {
if (actions_execute($action_name, $entity, $context) !== FALSE) {
$count++;
}
}
// Redirect the user the same as we would for $form_state['redirect'].
if (isset($context['redirect'])) {
actions_redirect($context['redirect']);
}
}
else {
backdrop_set_message(t('No items selected.'), 'error');
}
if ($count) {
backdrop_set_message(format_plural($count, '%action was applied to @count item.', '%action was applied to @count items.', array('%action' => $action_info['label'])));
}
}
}