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.
Comment | File | Size | Author |
---|---|---|---|
#1 | restore_square_barackets-2510838-1.patch | 918 bytes | junaidpv |
|
Comments
Comment #1
junaidpvHere 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.
Comment #2
junaidpvComment #3
NWOM CreditAttribution: NWOM commentedThis has worked perfectly. Thank you very much.
Comment #4
junaidpvComment #5
donaldp CreditAttribution: donaldp commentedThis also worked for me when I wanted to generate a link to a Solr search using /search/site?f[0]=....
Thanks for the patch.
Comment #6
renatog;
Comment #7
renatog#1 really makes sense
+1 to it
Comment #9
DamienMcKennaCommitted. Thank you.