views:

131

answers:

4

Hi. Can anyone tell me if it is possible to mix views arguments with static strings?

For example in the path section of a view feed display I need:

/mypath/%.xml

with the ".xml" part being the static string.

Thanks in advance.

A: 

I just tested this, and you can't do the exact path you posted above. Views appears to only recognize '%' as an argument placeholder if it sits between slashes, or by itself at the end. So, what will work is something like this:

/mypath/%/rss.xml

or

/mypath/static/%

jhedstrom
I was afraid of that. Our server admins won't allow /dir/index.xml
Aaron
Can anyone give me a hint on how I might write a module to extend views so that I could allow mixing path arguments with static strings?
Aaron
A: 

In path, anyway, you should set path/%
But you can check argument %.xml in validating code:
In views argument additing/editing window:
Validator options - Validator - PHP Code:

Enter PHP code that returns TRUE or FALSE. No return is the same as FALSE, so be SURE to return something if you do not want to declare the argument invalid. Do not use . The argument to validate will be "$argument" and the view will be "$view". You may change the argument by setting "$handler->argument".

Use strpos to check if there xml string. Also you can modify argument as it wrote in comment: $handler->argument

Nikit
A: 

You may change the argument by setting "$handler->argument".

How do I get this to work. I need to change the argument so that the changed argument is used in the SQL. I tried

$p = '/\.xml$/';

$argument = preg_replace( $p, '', $argument);
drupal_set_message( $argument );
$handler->$argument;
return TRUE; 

and all sorts of variants including:

$p = '/\.xml$/';
$argument = preg_replace( $p, '', $argument);
drupal_set_message( $argument );
$args[0] = $argument;
return $args;

I'm missing something here. Does the $handler take a function? Thanks in advance.

Aaron
A: 

I figured it out finally.

Under validation, choose PHP code. Then I entered:

    // strip ".xml" from incoming 
    $new_arg = preg_replace('/\.xml$/', '', $argument ); argument
    $handler->argument = $new_arg;
    return TRUE; //must return something

That works. Now Drupal sends "foo" to the SQL query, even if the incoming argument via the url is "foo.xml"

Aaron