Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#8 | incorrect_batch-2917340-8.patch | 3.51 KB | Graber |
| |||
#6 | interdiff.txt | 857 bytes | Graber |
#6 | incorrect_batch-2917340-6.patch | 2.93 KB | Graber |
| |||
#5 | incorrect_batch-2917340-4.patch | 2.93 KB | Leon Kessler |
|
Comments
Comment #2
Leon Kessler CreditAttribution: Leon Kessler commentedI'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...Comment #3
Leon Kessler CreditAttribution: Leon Kessler commentedHave 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).Comment #5
Leon Kessler CreditAttribution: Leon Kessler commentedWhoops, small typo in last patch (which lead to php error and failed tests).
New patch attached...
Comment #6
Graber CreditAttribution: Graber as a volunteer commentedLooks 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
.Comment #7
Graber CreditAttribution: Graber as a volunteer commentedA 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.
Comment #8
Graber CreditAttribution: Graber as a volunteer commentedOk, here's a solution that also works in block views.
Comment #10
Graber CreditAttribution: Graber as a volunteer commentedComment #12
Gonzalo2683 CreditAttribution: Gonzalo2683 as a volunteer commentedI 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?
Comment #13
Graber CreditAttribution: Graber as a volunteer commentedHi @Gonzalo,
Check
\Drupal\views_bulk_operations\Form\ViewsBulkOperationsFormTrait::getTempstoreData()
. You need to replaceredirect_url
parameter at some point (best when action execution is finished).