Support for Views Arguments

chaps2 - May 8, 2008 - 09:20
Project:AJAX Views
Version:5.x-1.4
Component:Code
Category:bug report
Priority:normal
Assigned:febbraro
Status:closed
Description

Great module, but I can't see why arguments are replaced with wildcards. Most of my views are pretty useless without their arguments. I had no problem changing _generate_ajax_url to suit but I'm curious as to why it's designed that way.

#1

febbraro - May 8, 2008 - 11:44

I was having problems when not replacing with the wildcard that nothing was showing up. I was not really relying on arguments for the data, but I can absolutely see how the views would be useless without them. It was my next bridge to cross. Were you having problems when the wildcards were in inserted? Also how are you specufy arguments to the views in What changes did you make and do you think they are generally applicable? If so I would gladly accept a patch. Thanks for using, I hope it helps you.

#2

chaps2 - May 9, 2008 - 16:27

My quick fix was suited to the fact that I'm using views within panel panes so it's easy to specify the ajax argument explicitly. I just return the views->real_url from _generate_ajax_url.

Otherwise I suppose it would be quite easy to get the arguments using $views->args[$argument['position']] when generating the url and use wildcards for missing arguments only.

Andy

#3

magoo - May 20, 2008 - 08:02
Category:feature request» bug report

this function:

<?php
function _generate_ajax_url($view) {
   
$url .= "$view->url";
    foreach (
$view->argument as $argument) {
        if(
$argument['type'] == 'ajax_response') {
           
$url .= "/ajax";
        }
        else if (
$argument['wildcard']) {
           
$url .= '/' . $argument['wildcard'];
        }
        else {
           
$url .= "/*";
        }
    }
    return
url($url);
}
?>

removes all the arguments.

As far as I understand, it replaces the arguments by either "*" or $argument['wildcard'] (configured wildcard). Never does it test the existence of the argument.

I replaced it with the following:

<?php
function _generate_ajax_url($view) {
   
$url .= "$view->url";
   
$i = 0;
    foreach (
$view->argument as $argument) {

        if(
$argument['type'] == 'ajax_response') {
           
$url .= "/ajax";
        }
        else if (
$view->args[$i]){
           
$url .= '/' . $view->args[$i];
        }
        else if (
$argument['wildcard']) {
           
$url .= '/' . $argument['wildcard'];
        }
        else {
           
$url .= "/*";
        }
       
$i++;
    }
    return
url($url);
}
?>

in order to copy the argument in the ajax call url.

I have it working with one argument (in addition to the AJAX pagination argument).

#4

febbraro - May 20, 2008 - 13:22
Assigned to:Anonymous» febbraro

hanks for digging into that. Also, have you had a chance to try it with more than one argument?

I will find some time soon to work this into a new release.

#5

magoo - May 21, 2008 - 06:11

Hello,

I have tested it with the following arguments list (in that order)

  • Taxonomy: Term ID
  • AJAX Views: AJAX Selector
  • Node: Type

and the block is called with this:

<?php
$t_view
= views_build_view('block', $view, Array($skill_term->tid, '', 'article'), false, false);
?>

the resulting url is:

<base_url>/<name_of_the_page>/68/ajax/article?page=0

and it works.

From my point of view, this is enough. The only problem in collecting the arguments is that

if ($argument['type'] == 'ajax_response') { ...
must be handled first and exclusively because we don't want the user to put a custom value in place of /ajax. This may change in the future, if the module adds more functionalities using the argument to differentiate calls.

Sorry for not posting a patch but the windows workstation at work is not my friend.

#6

febbraro - May 21, 2008 - 16:36

Magoo thanks for doing the leg work here. I have put your code in place and things look good from my perspective. I will commit this to CVS and create a new release.

Thanks again.

#7

febbraro - May 21, 2008 - 16:39
Status:active» closed
 
 

Drupal is a registered trademark of Dries Buytaert.