In an exposed view with bulk style, when the form is submitted via Ajax, the form action set by VBO is incorrect. This is introduced by http://drupalcode.org/project/views_bulk_operations.git/commitdiff/23d19c4

Example: in a view with two displays: a default display and a page display, if you call $view->get_path() it returns the path to the page display, not to the current display. Views uses this value as 'view_base_path', and VBO should not use it, instead, use 'view_path' (which is the value of check_plain($_GET['q'])) as in the old version.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kongoji’s picture

confirm the issue: I'm facing this problem when including VBO views in a Quicktabs block.
After every ajax submit of exposed filters, the next vbo operation redirects to the original view's path. It should redirect to the current url, not to the default view url.

kongoji’s picture

To make it work, as jcisio suggested, change view_path arguments in _views_bulk_operations_add_js function in views_bulk_operations.module.

replace

function _views_bulk_operations_add_js($plugin, $form_dom_id, $form_id) {
  static $views = NULL;
  if (!isset($views[$form_id])) {
    drupal_add_js(drupal_get_path('module', 'views_bulk_operations') . '/js/views_bulk_operations.js');
    drupal_add_js(drupal_get_path('module', 'views_bulk_operations') . '/js/json2.js');
    drupal_add_css(drupal_get_path('module', 'views_bulk_operations') . '/js/views_bulk_operations.css', 'module');
    drupal_add_js(array('vbo' => array($form_dom_id => array(
      'form_id' => $form_id,
      'view_name' => $plugin->view->name,
      'view_id' => _views_bulk_operations_view_id($plugin->view),
      'options' => $plugin->options,
      'ajax_select' => url('views-bulk-operations/js/select'),
      'view_path' => url($plugin->view->get_path()),
      'total_rows' => $plugin->view->total_rows,
    ))), 'setting');
    $views[$form_id] = TRUE;
  }
}

with

function _views_bulk_operations_add_js($plugin, $form_dom_id, $form_id) {
  static $views = NULL;
  if (!isset($views[$form_id])) {
    drupal_add_js(drupal_get_path('module', 'views_bulk_operations') . '/js/views_bulk_operations.js');
    drupal_add_js(drupal_get_path('module', 'views_bulk_operations') . '/js/json2.js');
    drupal_add_css(drupal_get_path('module', 'views_bulk_operations') . '/js/views_bulk_operations.css', 'module');
    drupal_add_js(array('vbo' => array($form_dom_id => array(
      'form_id' => $form_id,
      'view_name' => $plugin->view->name,
      'view_id' => _views_bulk_operations_view_id($plugin->view),
      'options' => $plugin->options,
      'ajax_select' => url('views-bulk-operations/js/select'),
      'view_path' => url(check_plain($_GET['q'])),
      'total_rows' => $plugin->view->total_rows,
    ))), 'setting');
    $views[$form_id] = TRUE;
  }
}
kongoji’s picture

Josh Benner’s picture

Status: Active » Needs review
FileSize
646 bytes

Solution mentioned in #3 has been committed to 6.x-1.x-dev, but does not fix this issue in all cases.

Solution mentioned in #2 is confirmed to work in my case. Patch attached.

Josh Benner’s picture

I should also note that this affects ajax pagers. This means that if you navigate the pager, then submit, the form action is wrong.

andrewbelcher’s picture

This is also an issue 7.x-1.x using a content pane inside a panel.

I solved it for my situation with the following:

/**
 * Implements hook_views_bulk_operations_form_alter().
 */
function mymodule_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) {
  if (isset($form_state['build_info']['args'][0]->override_url)) {
    $form['#action'] = url($form_state['build_info']['args'][0]->override_url);
  }
}

I wonder if extracting the view's path from the view is the way to go, as it is there as an argument for the form builder?

shi99’s picture

I tried out the patch from #4 and it resolved the issue I had with having an exposed filter and VBO on the same page.

It would be great if it could be committed.

bferretti’s picture

Alternate solution.

joelpittet’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)

Closing this as 6.x is no longer being maintained.