Tokenize

Please provide a token approach for generating captions. Basically we have two general situations: (1) token module enabled and (2) not enabled. For #1 - no comments needed. For #2 we could have the current ruleset for titles.

Subcaption

I would be over the moon if there was a separate, configurable, subcaption field. The subcaption would adopt tokens, and not render out at all if it were empty. This would allow for a nicer interface with actualy 2 lines of text. I would use first for the Node title, and the other for alt/title of the image.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rggoode’s picture

would it also be possible to allow for links to be in the caption? I have a view of gallery thumbnails from image nodes. I'd like to have people view the images from the gallery in Shadowbox, but then, if they want more information on an image while in shadowbox, click on a "view details" link in the caption adn go to the image node.

manfer’s picture

Status: Active » Closed (won't fix)

Not something related to shadowbox.

You may try to look at the module imageField Tokens or similar.

manfer’s picture

Status: Closed (won't fix) » Needs review
FileSize
10.34 KB

Borrowing code from colorbox module here is a patch to tokenize the captions

manfer’s picture

Version: 7.x-4.0-beta4 » 7.x-4.x-dev
manfer’s picture

Minor change on the patch to correct an issue with the visibility of tokenize form fields in views

moniuch’s picture

I have just had an opportunity to try out the patch. In general it applies and works, thanks for that.
I only regret the scope of available tokens is global and does not take the entity in account. But then I thought that for what I want to achieve actually the best option would be a title callback/hook. Something that would allow me to employ my own logic, such as:

function hook_shadowbox_get_caption($entity, $media_asset){
  // [...] code to get $entity_title and to prioritize $alt_or_title
  return (empty($alt_or_title)) ? $entity_title : $entity_title . ': ' . $alt_or_title;
}
manfer’s picture

With tokens you have access to the values of the file uploaded in the field. Using [file:field_file_image_title_text] and [file:field_file_image_alt_text] tokens you have access for example to the new media 2.x text and alt values.

But I have found a bug on this patch that makes it fail for the image field, I will upload a new patch as soon as possible.

moniuch’s picture

Still, in my case with tokens I would get "Node title:" when alt_or_title is not set. With a callback function I would have more flexibility to toss out the trailing colon.
Thanks for your immediate responses and patches though! Much appreciated!

manfer’s picture

I'm going to quote here an answer by David Reid to a similar problem

If you need logic in your tokens, then I'd probably suggest creating something using http://drupal.org/project/token_custom that is specific to your use case.

I think the custom token module (with the help of php filter module to allow PHP code on those tokens) is what you need to create your own specific tokens.

I'm going to modify this patch to correct the bug I found that makes tokens not work properly in the image field with shadowbox display format.

manfer’s picture