[development] Adding a query to every url

Ernst Plüss ernst.pluess at gmail.com
Fri Nov 19 19:55:54 UTC 2010


Hi Dave

Thanks for the hint. Furtunately url() flattens the query into a string if
it's an array, before it calls custom_url_rewrite_outbound().

Regards
Ernst



2010/11/19 Dave Reid <dave at davereid.net>

> Ernst,
>
> Keep in mind that $options['query'] can also be an array, so your code will
> fail if I try to do url('mypath', array('query' => array('foo' => 'bar'));
>
> Dave Reid
> dave at davereid.net
>
>
>
> On Fri, Nov 19, 2010 at 2:33 AM, Ernst Plüss <ernst.pluess at gmail.com>wrote:
>
>> Sorry for the noise! I Just realized that the $options array is passes by
>> reference to custom_url_rewrite_outbound as well. This means the correct
>> code looks like this:
>>
>> function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
>>      if (isset($_GET['iframe']) && 'on'==$_GET['iframe']) {
>>         $options['query'] .= (strlen($options['query'])>0 ? '?' : '') .
>> 'iframe=on';
>>     }
>> }
>>
>> Regards
>> Ernst
>>
>>
>> 2010/11/19 Ernst Plüss <ernst.pluess at gmail.com>
>>
>> Hi Drupalfriends
>>>
>>> I'd like to add a query string to every url. If the URL is '/node/234' it
>>> should change to '/node/234&iframe=on'.
>>>
>>> I found the custom_url_rewrite_outbound function and added it to my
>>> settings.php:
>>>
>>>     if (isset($_GET['iframe']) && 'on'==$_GET['iframe']) {
>>>         $path .= (strpos($path, '?') !== FALSE ? '&' : '?') .
>>> 'iframe=on';
>>>     }
>>>
>>> This works fine, but the url() method, which
>>> calls custom_url_rewrite_outbound runns $path through drupal_urlencode()
>>> afterwards. This means the url changes to  '/node/234%3Fiframe%3Don' which
>>> obviously does not work.
>>>
>>> Am I doing something wrong or is there another way of getting this to
>>> work?
>>>
>>> Regards
>>> Ernst
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20101119/08c45ec7/attachment.html 


More information about the development mailing list