Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tyler.frankenstein’s picture

Status: Active » Needs work

Sorry, this module only works with the 'Image' display format for image fields. I haven't yet tried Colorbox, I'll try it sometime and see if I can get the caption to work with it.

tyler.frankenstein’s picture

Title: Colorbox conflict » Colorbox module support
Assigned: Unassigned » tyler.frankenstein
Bernsch’s picture

Hy Tyler! Thanks for this nice module! :-)
I would also like to use with Colrobox ;-). I hope it will work soon.

marshallexcavating’s picture

Also, Thanks for this nice module! :-)

I would also like to use with Shadowbox module. Same problem as with Colrobox.

tyler.frankenstein’s picture

@marshallexcavating, I've added a separate issue for shadowbox support: http://drupal.org/node/1928348

maxiorel’s picture

Not ideal solution, but works: I've copied out function theme_colorbox_image_formatter($variables) {} to my template.php and renamed it to function MYTHEME_colorbox_image_formatter($variables) {}. Then to the last line with return theme(...) added
.'<div class="caption">'.$item['caption'].'</div>';

vgutekunst’s picture

@maxiorel

can u plz describe ur changes again (for dummies like me :) ) which template.php i have to change?

or can u make a patch?

regards

Bernsch’s picture

@maxiorel
Pleace paste your code for the template.php here. :-) Thanks!

tyler.frankenstein’s picture

Status: Needs work » Needs review

I have added support for the Colorbox module (http://drupalcode.org/project/image_field_caption.git/commit/bfe7cca) by providing a token for the caption:

[file:caption]

Update to the latest dev version of the module (http://drupal.org/project/image_field_caption) and flush your caches to get the token, or wait until the 7.x-1.1 version of this module comes out.

Here is how to set up the Image Field Caption token for use with Colorbox:

  1. Go to the 'Manage display' page for your content type, for example: Structure -> Content types -> Article -> Manage display
  2. Change the 'Format' to 'Colorbox' for your image field
  3. Click the gear icon to adjust the 'Format settings' for Colorbox
  4. Under 'Caption', select 'Custom (with tokens)'
  5. In the 'Custom caption' field, enter this token: [file:caption]
  6. Click the 'Update' button, then the 'Save' button
Dawn’s picture

Component: Code » Miscellaneous
Category: feature » support

I am looking for a way to allow an end user to add italics to just a portion of the caption. CSS would not be suitable, but rather a text formatter of some sort. I've tried a number of Modules including Image Caption Formatter, but no success so far with Colorbox. I have separate captions on the thumbnails and large images. I have achieved getting italics to show with just html italic tags in the caption that accompanies the thumbnail, but not over the large image where I need it.

Any help with this issue would be very appreciated. My site is not public, but I can send a link if it would be helpful.
Thanks.

tyler.frankenstein’s picture

Component: Miscellaneous » Code
Category: support » feature

@Dawn, this should be a separate issue because it is completely different than what is already being discussed here.

Bernsch’s picture

The [file:caption] token works with colorbox-field-formatter but the display-settings on my contentype doesent works correctly.

The [file:caption] token text always show in teaser-node but not on my full node.
When i am create a full-node display and use the [file:caption] token, the caption-text does not show in my full-node view - only in my teaser-view! In my manage displays settings for my contenttype i use not a colorbox-field-formatter on my teaser-view!

Should we open a new issues for this problem?

Bernsch’s picture

Version: 7.x-1.0 » 7.x-2.x-dev
Status: Needs review » Active

[file:caption] tokens also doesn't work in 2.x branche ...

hanoii’s picture

the token was removed, and the caption is not associated wiwth the file no more but rather with the entity, token support, differently, has to be properly added.

hanoii’s picture

Status: Active » Postponed

I have spent a considerable time on this and I don't see it included in this module. Here are my reasons:

I could do something similar to the file token attempt done by tyler on the 1.x branch, however, the 1.x branch was storing the caption associated with a file, which caused a lot of different issues.

By looking at the colorbox module, I could still use the file token as before, only because colorbox send a similar file object to the token function, although it's not really a file object. By defining a file token such as this, it will only work for the colorbox module, and the file token will appear for other file token uses and I think it can add confusion, still think it I might add this at some point but I will explore other options and I don't have that much time right now.

Also, there's another issue here, because doing it either way, the colorbox module expects the caption to be on the title tag of the image for it to work, and because this module now accepts any filtered text (such as HTML) this may cause extra issues.

I am going to posponed this for now, mainly because if you really need colorbox support, you can override the colorbox formatter theme implementation in your theme and do as needed.

I submitted this to #2014853: Caption alterers colorbox, if accepted I might work something out following that idea.

hanoii’s picture

Also, bear in mind that you can use the title tag for the colorbox caption and leave the caption field to be used somewhere else. You can also override the colorbox formatter to show the html caption on the code.

hanoii’s picture

hanoii’s picture

There's also the fact that to add the caption as an HTML to the full view, colorbox has its own formatter which means unless you override again the formatter, it's not really the work of this module to support colorbox or other lightbox alternatives.

I suggest add a feature request in the colorbox module to support this module's caption. That might be easier or even better that the other way around.

If you do please realate it here.

hanoii’s picture

Assigned: tyler.frankenstein » Unassigned
AaronBauman’s picture

Here's how i exposed image_field_caption tokens for my own project, in case anyone else needs this functionality:

function mymodule_token_info() {
  $info['tokens']['file']['image_field_caption'] = array(
    'name' => t('Image Field Caption'),
    'description' => t('The image caption, if enabled.'),
  );
  return $info;
}

function mymodule_tokens($type, $tokens, $data = array(), $options = array()) {
  if ($type != 'file' || empty($tokens['image_field_caption']) || $tokens['image_field_caption'] != '[file:image_field_caption]' || empty($data['file']) || empty($data['file']->image_field_caption['value'])) {
    return;
  }
  $options = array_merge(array('language' => LANGUAGE_NONE, 'sanitize' => TRUE), $options);

  $caption = check_markup($data['file']->image_field_caption['value'], $data['file']->image_field_caption['format'], $options['language']);
  if ($options['sanitize']) {
    $caption = filter_xss($caption);
  }
  return array('[file:image_field_caption]' => $caption);
}

Road Kill’s picture

Hi is there away to get his caption field to pull through in views in a slideshow with images.

Road Kill’s picture

Sorry my bad I see it pulls through automatically :) nice

corkis81’s picture

Issue summary: View changes

Hi, I have read several pages of tokens but I know little about php.
I tried to use #20 but I'm not sure how to implement colorbox.

could someone help me to create the files or module right?

Thank you so much

ardarvin’s picture

I'm using 2.x branch. Hopefully this helps someone. I have a content type of "portfolio" with an image field machine name "field_portfolio_content_image" which can take in multiple images. I have a custom node---portfolio.tpl.php for this. As I want to display each image as a "lightbox" I can't simply:

render($content['field_portfolio_content_image']);

which works fine, but I can't get my lightbox. It took some time, but I found how to force the comment to display:

<?php echo $node->field_portfolio_content_image['und'][$img_count]['image_field_caption']['value']; ?>

the key is ['image_field_caption']['value']. Code in context looks like this:

<?php 
$items = field_get_items('node', $node, 'field_portfolio_content_image');
$img_count = 0;
$counter = count($items);
?>

<?php while ($img_count < $counter) { ?>
      <a href="<?php echo file_create_url($node->field_portfolio_content_image['und'][$img_count]['uri']); ?>" class="portfolio-lightbox-image"><img src="<?php echo file_create_url($node->field_portfolio_content_image['und'][$img_count]['uri']); ?>" alt="<?php print $title; ?>" /></a>
      
      <?php if (!empty ($node->field_portfolio_content_image['und'][$img_count]['image_field_caption']['value'])) : ?>
      <blockquote class="image-field-caption">
  		<?php echo $node->field_portfolio_content_image['und'][$img_count]['image_field_caption']['value']; ?>
	  </blockquote>
	  <?php endif; ?>
	  
<?php $img_count++; } ?>	
 
neomen’s picture

Hi guys.
For myself, made a small fix. Maybe they will be useful to someone else.

bellagio’s picture

#25 works great. thank you!!

Bernsch’s picture

Status: Postponed » Needs review
iStryker’s picture

Status: Needs review » Needs work

Do not like this method. like https://www.drupal.org/node/2345635#comment-9706103

Instead of overwritten the colorbox_image_formatter, we create our own formatter called 'Colorbox with caption'.

Plan to finish this today as I need it for a project I am working on.

Shane Birley’s picture

Is this code ready?

iStryker’s picture

@Shane the code in the patch hijacks colorbox theme registry. This allows it to work. You may use it, but know that this solution will not be commit.

Shane Birley’s picture

Anyone need help with this? It would be an awesome feature to release.

vistree’s picture

Hi,
#25 works great - even with html enabled. I needed to change it a little bit to work with current 2.1-dev-11 version - but the result is amazing!
Why not to commit it? It checks for existing colorbox - so it is safe if colorbox is not installed ....

Leagnus’s picture

#20 is good for module_name.tokens.inc – it adds custom token to "manage/Your_type_of_material/display" > Colorbox format for a field > Caption > Custom (with tokens).
Its for CB lightbox` captions.

#25 works great for image_field_caption 7.x-2.1 – it adds the caption into blockquote html tag below an image.
Its for full node page.

thomas.frobieter’s picture

+1 for patch #25 caption is working with the colorbox formatter now - thx!

Anybody’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
1.56 KB

Tested and re-rolled patch from #25. Patch against latest 7x.-2.x-dev attached. Thank you all. Please confirm RTBC.

Anybody’s picture

New patch including #20 + #25 so now we have the token: [file:image_field_caption] available for colorbox subtitle PLUS working caption below preview images. Made for 7.x-2.x-dev!

Working perfectly for us. Please review.

Anybody’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
2.91 KB
heliogabal’s picture

Status: Needs review » Needs work

Tested patch #36 with 2.2 (which is basically the same as dev):

1. First I got the following error:

patch -p1 < image_field_caption_colorbox-1913352-36.patch
patching file image_field_caption.module
patch unexpectedly ends in middle of line
patch: **** malformed patch at line 70:

2. When I added an empty line to the end of the patch, it applied cleanly.

3. I get the caption on the default node view with the colorbox field formatter now, that before only worked with the image formatter. So first part of the patch is working for me.

4. To also have the caption on the opened colorbox, I had to select Subtitle: Custom (with tokens) on the colorbox field formatter, and put [file:image_field_caption] into the custom subtitle field. So second part of the patch also working.

5. Of course, with the token substitution, I lose all my formatting from the image_caption_filter field, but that's out of scope for this issue, I guess.

raywalters’s picture

This patch keeps the image caption field when using colorbox.

raywalters’s picture

Status: Needs work » Needs review
ZapevalovAnton’s picture

Patch #39 not work for me.(((

Anybody’s picture

Status: Needs review » Needs work

The patch from #37 doesn't apply anymore, but definitely worked for me with 7.x-2.1+12-dev. It needs a reroll against the latest dev.

#39 misses the module check for example... I think #37 is a better starting point. #38.5 should be handled in a separate issue I think.

iStryker’s picture

Status: Needs work » Closed (outdated)

Marking all 7.x as out of date. If the problem persists, then only a new issue.