On a multilingual site, when I execute a bulk operation on a selection of rows, while displaying the site in a non-default language, the next screen (usually confirmation screen) switches to the site default language.

This is quite annoying, as I want to use VBO views for a content admin role for a person not equally proficient in all languages, and would definitely expect all steps to be executed preserving currently selected language.

I assume path prefixes are not correctly appended, though the URL does not change (ajax call?).

Thanks in advance!

Comments

marktheshark’s picture

Issue tags: +language, +i18n, +default, +views, +bulk, +locale, +vbo, +operations
marktheshark’s picture

Any input on this please?

Architeck’s picture

Your not alone, I am experiencing a very similar issue:

When I apply VBO actions the form action does not include the language prefix and in my case throws a 403 error. If I manually edit the action with firebug to include the prefix, the actions are successfully executed.

I have been trying to track down the right combination of translation (language prefix handling) and vbo settings, but thus far have not come up with a solution.

Using:

Views - 6.x-2.12
Views Bulk Operations - 6.x-1.10
Internationalization - 6.x-1.8

marktheshark’s picture

Haven't looked at the code, but perhaps the form action element is not wrapped in an l() function that would automatically take i18n into account?

jaxxed’s picture

The VBO modules doesn't properly handle url rendering in it's core. here is a description of the problem, the relevant code, and a fix (at the bottom) that has been tested in one environment only.

Please see hook_form in views_bulk_operations.module:184

Here are the relevant lines: ~199

  if (!$once) { // We can be called here twice.
    drupal_add_js(array('vbo' => array('url' => $_GET['q'])), 'setting');
    $once = TRUE;
  }

The module is attempting to bypass the current url, by pulling the Drupal URL parameter directly. This fails in any rewritten url cases, including localization. This is considered bad form in Drupal, but is sometimes implemented in cases where Drupal modified urls prevent access to actual menu routes, but this was more of a Drupal 5 technique than 6. Form are in general not a case where pulling the 'q' variable is necessary.
That being said, there amy be a reason why the VBO devs have pulled the GET[q] directly.

The drupal_add_js adds the key url=$_GET['url'] to the Javscript Drupal.settings array, which is then used to pick a target for ahah.ajax form submits.

Once could use the Drupal url() function to include the rewrites with a small change:
DON'T USE THIS CODE, FOR REASONS DESCRIBED BELOW

  if (!$once) { // We can be called here twice.
    drupal_add_js(array('vbo' => array('url' => url($_GET['q']) )), 'setting');
    $once = TRUE;
  }

When I implemented this, I found that the language specific prefix was now included in my forms, however that being said, the forms redirected to an absolute url becuase url puts a leading slash on the url, while the form creation script also adds a leading slash. This lead to the form submitting to an invalid absolute url (http://en/view/display) instead of a relative url (http://site.root/en/view/display.) To fix this I took of the leading slash with a substr().

THIS CODE WORKED FOR ME, BUT TEST IT IN YOUR ENVIRONMENT FIRST

  if (!$once) { // We can be called here twice.
    drupal_add_js(array('vbo' => array('url' => substr(url($_GET['q']),1) )), 'setting');
    $once = TRUE;
  }

This has been tested on a single site that uses a root url (no subfolders.) If someone is willing to test it on a site that uses a folder path in the url, then I would consider writing this as a module patch and submitting it to the module developers.

The overalll patch is something like:

-199:     drupal_add_js(array('vbo' => array('url' => $_GET['q'])), 'setting')
+199:     drupal_add_js(array('vbo' => array('url' => substr(url($_GET['q']),1) )), 'setting');
jaxxed’s picture

Priority: Normal » Major
Status: Active » Needs review

Upgrading priority: this issue effectively makes all VBO operations on multilingual sites inoperative. Localization is a core feature, even though it's not enabled by default.

Module Developer: Please consider investigating the fix I've included above (Comment: #5) I've tested the fix on one or two sites, but am unsure why the url function wasn't used in the first place.

infojunkie’s picture

Thanks for the analysis. I am currently working on a major fix to VBO's selection mechanism which involves getting rid of the code above. I hope to release this during this week.

infojunkie’s picture

Version: 6.x-1.10 » 6.x-1.x-dev

I committed the major fix mentioned above. Please test your scenario again and let me know if it works.

marktheshark’s picture

I will try to test this on my local site instance tomorrow and provide feedback. Thanks for your effort!

marktheshark’s picture

Installed latest 6.x-1.x-dev version, and flushed Views cache. Language switch is not observed anymore. VBO views retain selected language.

Will this be ported to the Recommended Version?

Thanks again everybody for your support! :-)

infojunkie’s picture

Status: Needs review » Fixed

Yes, this fix will be included in next release. Thanks for your feedback!

Status: Fixed » Closed (fixed)

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

tobiberlin’s picture

Status: Closed (fixed) » Needs work

Hi,

re-open this issue: I tried it and found a problem when I run my site within a subfolder:

Let's say my site runs on http://www.mysite.com/subfolder/ where "subfolder" is the root directory of my drupal installation. Then when I try to use VBO on http://www.mysite.com/subfolder/vbo and start an action I am lead to http://www.mysite.com/subfolder/subfolder/vbo when I applied this patch to my vbo module (version 6.10).

Best,
Tobias

infojunkie’s picture

@tobiberlin: are you using the latest dev?

jaxxed’s picture

@tobeiberlin: do you still have this issue? is it with the latest code?

If so, then can you please revert the above patch to see if it is the cause of the problem. It's been some time since I wrote it, so I don't remember the whole code base for it. It seems to me that the 'url' function should be able to handle subfolder sites.

@infojunkie: do you think that the patch caused the problem?

infojunkie’s picture

@jaxxed: I didn't use your modification because the JavaScript code that computes the form action had changed in the mean time.

bojanz’s picture

Status: Needs work » Closed (fixed)

#13 appears to be using a non-supported patch, instead of a version (6.x-1.11, 6.x-1.x) which has a better fix included.