Hi,

When we rewrite a field output in view, we are supposed to give %5B and %5D to get [ and ] respectively in rewritten output. But it remains as %5B and %5D, which leads to following issue.

If we want to generate a link that contains [ and ], using a rewritten field. We need to use %5B and %5D instead of literal [ and ]. But generated link will be processed by drupal_http_build_query(), then %5B and %5D will get converted to %255B and %255D as % get escaped.

It is essential to have [ and ] in some cases, for example when using prepopulate module to prefill the node field values in creation form using values from existing nodes.

Example:

We want to generate the link of pattern /node/add/page?title=Somevalue&edit[field_something][und]=somevalue

Assuming we have added field_something and title field in view. Then first we can rewrite the output of field_something with this: &edit%5Bfield_something%5D%5Bund%5D=[field_something-value]

Then we can add a 'Global: Text' to generate the link, with link path: node/add/page?title=[title][field_something]

Output of 'Global: Text' will generate link similar to node/add/page?title=somevalue&edit%5Bfield_somefield%5D%5Bund%5D=somevalue , but it get processed by drupal_http_build_query() creating link 'node/add/page?title=somevalue&edit%255Bfield_somefield%255D%5Bund%255D=somevalue after escaping % characters. Which will not work with prepopulate module as we intended.

See last three comments (#4, #5 and #6) of https://www.drupal.org/node/578772 , they are facing similar issue.

To avoid this issue we need to convert %5B and %5D to literal [ and ] once token replacement has been performed on the field output.

I will post a patch proposing a fix to this issue.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

junaidpv’s picture

Here is the patch fixing the issue. It works with normal fields but not sure exactly whether it will restore square brackets in 'Global: Text' also.

junaidpv’s picture

Status: Active » Needs review
NWOM’s picture

Status: Needs review » Reviewed & tested by the community

This has worked perfectly. Thank you very much.

junaidpv’s picture

Assigned: junaidpv » Unassigned
donaldp’s picture

This also worked for me when I wanted to generate a link to a Solr search using /search/site?f[0]=....
Thanks for the patch.

renatog’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
FileSize
16.17 KB

;

renatog’s picture

Status: Needs work » Reviewed & tested by the community

#1 really makes sense

+1 to it

  • DamienMcKenna committed ffa1154 on 7.x-3.x authored by junaidpv
    Issue #2510838 by junaidpv, RenatoG, NWOM, donaldp: Need to convert %5B...
DamienMcKenna’s picture

Status: Reviewed & tested by the community » Fixed
Parent issue: » #3054023: Plan for Views 7.x-3.24 release

Committed. Thank you.

Status: Fixed » Closed (fixed)

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