I know this issue has come up before, but I couldn't pinpoint a thread to refer to, so I apologize if I am rehashing anything here.

We had a need for inserting a customizable link to the Colorbox caption, which isn't possible using the "title" field. So I came up with a solution for the 7.x-1.x version. We'd like to move to 7.x-2.x, so I thought I'd try and rework the solution and share as a patch.

The attached images show the end goal - a customizable field for "Link on caption" both in Views (on a per image basis) and on the Content Type display interface (set once for all images - though using tokens could individualize).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mxwright’s picture

And a patch

mxwright’s picture

FileSize
13.42 KB

Unfortunately, the downside to this patch, or this method in general, which adds a new "url" field to the colorbox href surrounding the image, is that you have to also modify the colorbox library so that the new field will be picked up. The changes are small but significant and the patch can't work without them. If someone has a better method for hooking the changes in, rather than modifying the library, that would be great. In the meantime, here are the fully modified jquery.colorbox.js and jquery.colorbox-min.js files. Just unzip and drop them into your Colorbox library directory.

mxwright’s picture

FYI, I am working on a new version of the patch that operates more like the "Caption" field, allowing the field to be set to "title text", "alt text", "custom (with tokens)", or "none". That way, one could utilize the alt text, for example, to set a link on an individual level when not using Views. That one is hopefully forthcoming.

mxwright’s picture

Status: Active » Needs review
mxwright’s picture

FileSize
13.45 KB

Corrected mistake in colorbox library where items using "colorbox-load" class would not load due to missing "url" parameter. Disregard upload in #2 above. Should work now.

mxwright’s picture

OK, here's the new version of the patch, featuring title, alt text, and custom/tokens.

mxwright’s picture

FileSize
137.89 KB
81.3 KB

The patch in #6 above should have a slightly updated look on the admin side, as evidenced by the two attached pics. It now looks and acts much like the "Caption" field.

rooby’s picture

Why is this a new field at all?

What about just allowing colorbox_caption_custom to accept and render links?

The title attribute can contain links, however they need to have their html entities encoded. What makes it not possible is the use of Drupal's l() function to create the link. That function will stop you putting links in the title attribute.

In my case I overrode that theme function and manually created the a tag markup instead of using l() and then I could put links in there.

If we changed the original theme_colorbox_imagefield() function it would likely solve this without having to have the additional fields and javascript.

userspan’s picture

FileSize
177.67 KB
Neslee Canil Pinto’s picture

Status: Needs review » Needs work

Patch failed to apply.

Neslee Canil Pinto’s picture

Status: Needs work » Closed (outdated)