Hi,
Nice module, however i believe i have found a bug/oversight in the code.
In the hook_menu on line 69 there is the following code:
$urls = views_get_all_urls();
foreach ($urls as $key => $url) {
if ($url && strpos($_GET['q'], $url) !== FALSE) {
$view_name = $key;
break;
}
}as far as i can tell this is just searching for the existence of the current url ($_GET['q']) within any of your views.
I ran into a problem, however, because i had some views with similar urls.
eg
I had a pre-existing view at /tracker.
I went to add another view is at /growth-tracker.
However the above code found the view at /tracker before it found my new one and as a result my new view just didnt work: I couldn't go to /operations to set an operation for vbo and the view just returned nothing.
I propose that you should replace the previous code with the following
else {
$current_url = $_GET['q'];
// See if the current url ends in /operations; if so, strip it off so we can see if that matches the path
if (substr($current_url, -11) == '/operations') {
$current_url = substr($current_url, 0, (strlen($current_url) - 11));
}
$views_urls = views_menu(false); // get the non-cached views menu handlers
foreach ($views_urls as $url) {
$view_path = $url['path'];
if (strpos($current_url . '/view', $url['path']) === 0) {
$view_name = $url['callback arguments'][0];
$path = $current_url . '/operations';
break;
}
}
rather than searching all the views urls on your intsall, this looks at the current views menu handlers to retrieve the view's url.
Patch is attached
What do you think?
Josh
| Comment | File | Size | Author |
|---|---|---|---|
| vbo-find-view-name.patch | 1.25 KB | sonictruth |
Comments
Comment #1
sonictruth commentedPS sorry about the formatting on that second piece of code, something went amiss in my copy and paste :\
Comment #2
infojunkieFixed in the latest dev release, but with different code. Please try it and let me know (after the obligatory 12 hours wait for Drupal.org to refresh the release).
Comment #3
jeff h commentedThanks Kratib for getting onto this so quickly... to be honest I haven't tried it yet but I'm a little sceptical about some parts of your version of this patch compared with Josh's.
What if I build a view at this url: something/view/stuff
That'll match your strrpos in line 69 yes? Should be easily gotten around though :)
Jeff
Comment #4
infojunkie@Jeff thanks for pointing this out. Yes my code would incorrectly match your view, so I modified the matching function to make sure the '/view' part appears at the rear of the string. This will also not work if you create a view with a URL *ending* with /view, but I wonder what that would do to the core Views module!
Also note that Josh's code was incorrect in that if $current_url == 'view_url/clone', then it wouldn't be matched and thus the operations tab would not appear. Maybe that's what he intended but that's not what I intend.