You are here

function views_bulk_operations_direct_adjust in Views Bulk Operations (VBO) 7.3

Adjusts the selection for the direct execution method.

Just like the direct method itself, this is legacy code, used only for aggregate actions.

1 call to views_bulk_operations_direct_adjust()
views_bulk_operations_execute in ./views_bulk_operations.module
Entry point for executing the chosen operation upon selected rows.

File

./views_bulk_operations.module, line 1167
Allows operations to be performed on items selected in a view.

Code

function views_bulk_operations_direct_adjust(&$selection, $vbo) {

  // Adjust selection to select all rows across pages.
  $view = views_get_view($vbo->view->name);
  $view
    ->set_exposed_input($vbo->view
    ->get_exposed_input());
  $view
    ->set_arguments($vbo->view->args);
  $view
    ->set_display($vbo->view->current_display);
  $view->display_handler
    ->set_option('pager', array(
    'type' => 'none',
    'options' => array(),
  ));
  $view
    ->build();

  // Unset every field except the VBO one (which holds the entity id).
  // That way the performance hit becomes much smaller, because there is no
  // chance of views_handler_field_field::post_execute() firing entity_load().
  foreach ($view->field as $field_name => $field) {
    if ($field_name != $vbo->options['id']) {
      unset($view->field[$field_name]);
    }
    else {

      // Get hold of the new VBO field.
      $new_vbo = $view->field[$field_name];
    }
  }
  $view
    ->execute($vbo->view->current_display);

  // Call views_handler_field_entity::pre_render() to get the entities.
  $new_vbo
    ->pre_render($view->result);
  $results = array();
  foreach ($view->result as $row_index => $result) {

    // Set the row index.
    $view->row_index = $row_index;
    $results[$row_index] = $new_vbo
      ->get_value($result, $new_vbo->real_field);
  }
  $selection = $results;
}