When using a subpath (e.g. http://www.example.com/uk) on your site, the redirect at the end of a VBO batch operation is incorrect.

Steps to reproduce:
1) Load your site using a subpath (can do this by creating a symlink)
2) Navigate to a view with VBO enabled, e.g. http://www.example.com/uk/admin/content
3) Process some action

Expected result:
You should be redirected back to the page you were on (http://www.example.com/uk/admin/content)

Actual result:
You are redirected to http://www.example.com/uk/batch, which is a 404

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Leon Kessler created an issue. See original summary.

Leon Kessler’s picture

I've had a look into this, and the issue comes from here:
Plugin/views/field/ViewsBulkOperationsBulkForm.php line 625:
$data['redirect_uri'] = $this->getDestinationArray();

The destination parameter is used later in ViewsBulkOperationsController.php line 48:
return batch_process($view_data['redirect_uri']['destination']);

So at this point, using the example above, the destination parameter will be /uk/admin/content.

The issue is that this get's passed into batch_process(), which eventually attempts to convert it into a Url object. Because it's not a valid path, it switches it to the current one (which is /batch). See: http://cgit.drupalcode.org/drupal/tree/core/includes/batch.inc?id=e5713b...

Leon Kessler’s picture

Status: Active » Needs review
FileSize
2.93 KB

Have fixed this by getting the url object directly from the View. Not sure why this wasn't done in the first place - perhaps for if there was already a destination on the request?

I do think that this module's current use of getDestinationArray() is not correct. As per the documentation: Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. which this module is not doing (it's extracting the destination and using that data by itself).

Status: Needs review » Needs work

The last submitted patch, 3: incorrect_batch-2917340-3.patch, failed testing. View results

Leon Kessler’s picture

Status: Needs work » Needs review
FileSize
2.93 KB

Whoops, small typo in last patch (which lead to php error and failed tests).
New patch attached...

Graber’s picture

Looks ok, but we don't have to use the $this->getView() method inside the view field plugin, as view object is available internally. Changed to $this->view.

Graber’s picture

Status: Needs review » Needs work

A view containing VBO field can be in a block. In such a case the $this->view->getUrl() method throws:

InvalidArgumentException: You cannot create a URL to a display without routes.

We need to get the URL in a different way.

Graber’s picture

Status: Needs work » Needs review
FileSize
3.51 KB

Ok, here's a solution that also works in block views.

  • Graber committed 0061da6 on 8.x-1.x
    Issue #2917340 by Graber, Leon Kessler: Incorrect batch finished...
Graber’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Gonzalo2683’s picture

I do not know if it's the place to consult, @Graber, a question, is there a way that once the custom action ends up redirecting to a different URL than the default one?

Graber’s picture

Hi @Gonzalo,

Check \Drupal\views_bulk_operations\Form\ViewsBulkOperationsFormTrait::getTempstoreData(). You need to replace redirect_url parameter at some point (best when action execution is finished).