Hi,

with the last 7.x-3.x-dev branch, i have a notice in the get_render_tokens method of views_handler_field object :
Notice: Array to string conversion in views_handler_field->get_render_tokens() (line 1381 of /var/www/vivien/htdocs/drupal-7.14/profiles/nvision/modules/contrib/views/handlers/views_handler_field.inc).

There's in this part of code :

foreach ($_GET as $param => $val) {
  if (is_array($val)) {
    $val = implode(', ', $val);
  }
  $tokens['%' . $param] = strip_tags(decode_entities($val));
}

The reason is simple : maybe the $val var contains an array to. For exemple, in the date module, the $val is something like :

$val['value']['year'] = '2012'. 

2 solutions i think :
- force others modules to cleanup $_GEt parameters before sending it to the browser
- allow views tokens to manage this kind of parameters

The second solution is the best of course :), Coders could have more flexibility.

A recursive implode could be a solution.

Thx.

Comments

dawehner’s picture

What about just another level of hierarchy? This would be somehow easy to do but you know recursive should work as well.

Your first suggestion would probably be too hard, as this requires people to change fapi-structure which is hard.

VivienLetang’s picture

Yes, the simple way is to add another level. I will suggest a patch soon.

Thx for the reply

damiankloip’s picture

Status: Active » Needs review
StatusFileSize
new663 bytes

We could use some SPL iterators to deal with this, then it doesn't matter how deep the nesting is in the query string. It keeps it nice and clean too. Patch attached.

BeaPower’s picture

Getting this error too, has a fix been committed?

dawehner’s picture

@Beapower: If it would be committed, the status wouldn't be "needs review" anymore, simple :)

The code itself is nice, at least some structures of php are actually nice ...
About the actual fix, shouldn't sub-elements have a different key to access them?

damiankloip’s picture

We could easily get the depth of the element key returned and use that? or do you want something that appends the keys together instead?

damiankloip’s picture

StatusFileSize
new846 bytes

Something more like this maybe?

damiankloip’s picture

StatusFileSize
new1.91 KB

Here is a new idea, this is actually much better. So it will iterate recursively over the query array and create a nested token structure. So a query string like this :

....?param[foo][a]=test&param[bar][a]=test&param[foo][bar][a]=test

Will create the following set of tokens:

%param_foo_a => test
%param_foo_bar_a => test
%param_bar_a  => test
%q => whatver q param

At the moment the patch uses a function inside the method, so then it can call this recursively, plus it's only being used there. Do you think it would be better if this just used it's own method instead? Incase it needs to be used somewhere else again (you never know)?

Status: Needs review » Needs work

The last submitted patch, 1566770-8.patch, failed testing.

damiankloip’s picture

Status: Needs work » Needs review
StatusFileSize
new3.07 KB

Sorry, that just wouldn't work like that. Here is a proper version, creating a get_token_values_recursive method instead. Complete with comments etc...

Should there maybe be another parameter in this method to choose the token prefix? incase it needs to be used elsewhere ever. i.e. % or ! etc...

damiankloip’s picture

StatusFileSize
new3 KB

or we just ditch the RecursiveArrayIterator, probably not much point if we use a function to get the tokens now!

damiankloip’s picture

StatusFileSize
new2.97 KB

Here is an updated version with the right docblock text.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Looks perfect now!

dawehner’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the work, committed to 7.x-3.x and 8.x-3.x

VivienLetang’s picture

Nice work. Thx to all

KingSalibah’s picture

Patch worked for me!

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

code tag