Hi, I am having a problem in connection with using a rewrite on a field that has [token]-like values in it causing unintended results in views output.

'field_video_upload_fid' => array(
    'label' => 'Video',
    'alter' => array(
      'alter_text' => 1,
      'text' => '<a href="[field_video_upload_fid]" rel="lightvideo[|width:400px;height:300px;][caption]">[title]</a>',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'widget',
    'format' => 'url_plain',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_video_upload_fid',
    'table' => 'node_data_field_video_upload',
    'field' => 'field_video_upload_fid',
    'relationship' => 'none',
  ),

The text in the rel="..." argument is supposed to be specific to lightbox2 and it seems like views is parsing the [] brackets and having a hard time with it. Maybe you guys can help with a solution. Lightbox2 forum had me experimenting with filters to no avail #483798: rel attribute lightframe disappears if I fill in a width.

The processed results of this code comes into the browser as:

<a href="http://localhost/sites/default/files/video/Wildlife.wmv" rel="300px;][caption]">Media node</a>

You can see, the text in the rel= is very mangled

First, if this is just a poor way for lightbox to get its parameters considering it supports views and [] are a universal token parameter, is there an easy way I can escape the [ open bracket parsing? I tried a backslash... and tried single quotes. I also tried turning off lightbox, using zzz="..." as the parameter, changing lightbox to any text... it's like a magic sequence in the *[|width:400px;height:300px;]* sequence that's breaking the output from Views.

I am looking forward to your considered response!

-- glen

Comments

glen201’s picture

Bump?! Anyone know how to escape the [] in a rewrite field?

jascott’s picture

Category: bug » support
Status: Active » Closed (works as designed)

Re-write with brackets using HTML special chars &#91; (left square bracket) and &#93; (right square bracket):

<a href="[field_photo_fid]" rel="shadowbox&#91;[name]&#93;">[name]</a>

This works in the 'Rewrite the output of this field' option because it allows HTML. The 'Output this field as a link' option does not allow HTML.

Changed category to 'support request' and 'by design'.

ahb’s picture

Category: support » bug
Status: Closed (works as designed) » Needs review

This actually has the same effect as it did with unescaped []

merlinofchaos’s picture

Priority: Critical » Normal
Status: Needs review » Active

'needs review' means it has a patch applied.

'critical' is reserved for crash bugs.

wgrunberg’s picture

I was able to successfully escape [ and ] in URL's by using URL safe encoding (hex).
[ = %5B
] = %5D
I am generating "Add Content" links with prepopulated content (http://drupal.org/project/prepopulate). It works great with my CCK fields!

merlinofchaos’s picture

Component: Views Data » Documentation
Category: bug » task

Oh! Good catch!

This workaround should be added to the documentation right there with the replacement tokens so everybody can find out about it.

Jerome F’s picture

That is also a workaround to use a lightbox in an url rewrite.

http://drupal.org/node/738670

Jerome F’s picture

Actually it isn't I tested it with no success, but nevermind for that use case there is the lightbox views trigger.

tallsimon’s picture

Just what I was looking for wgrunberg thanks!

3rdLOF’s picture

This issue can be solve by doing a very simple patch to the lightvideo.js file as described here:

http://drupal.org/node/483798#comment-2263568

The problem are not the brackets but the colon separators.

Now, Jerome had the right idea with the ;ightbox trigger EXCEPT if you want to pass extra fields within the lightbox rel call.

In my case I have created a video recipe that uses a width and height fields in the submission form. I wanted to pass that info to the lightvideo rel via tokens, so using lightbox trigger would not work.

This small mod changes the ":" to a "=" and it takes of the problem.

Example: <a href="[field_video_fid]" rel="lightvideo[|width=[field_video_width_value]px; height=[field_video_height_value]px;]">[field_video_thumbnail_fid]</a>

Now if I can just automate the collection of the video dimensions upon upload I will be a happy man.

Jerome F’s picture

@ kannary

Did you do this patch or did you directly hack the module file ?

iamjon’s picture

StatusFileSize
new897 bytes

I've created a patch to document the work around in comment 5 http://drupal.org/node/567918#comment-2381656
Hope it helps

iamjon’s picture

StatusFileSize
new2.09 KB

I'm re-adding but this time with context...I hope.

iamjon’s picture

StatusFileSize
new1.98 KB

So apparently patches and me aren't friends.
Here is my third attempt.

iamjon’s picture

Status: Active » Needs review
StatusFileSize
new1.55 KB

one day people will point to this and say...and that's how he learned to patch

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

And you will say look back and see a lot of patches from yourself.

Take care of youself, i did the same 1,5 years ago and then i got a bit involved.

merlinofchaos’s picture

Status: Reviewed & tested by the community » Fixed

Committed to all branches.

Congrats on getting your first patch in!

Status: Fixed » Closed (fixed)

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