I'm trying to use colorbox together with inline (7.x-2.x). What i need is a way to render a image field with multiple values, but somehow be able to choose the image to display (ie. if i attach 3 images on the image field, i want to render just the first image)

I need this as i have a blog content type, with just 1 extra image field with ilimited values, so i can attach lots of images there. Then when i write the blog, i can :

write some text...

insert first image...

write some more text...

insert second image...

write some more...

insert third image.

Any idea on how to achieve this? Thanks a lot!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

frjo’s picture

I do not understand what you are after regarding the Colorbox module.

Does the inline module have some sort of Colorbox integration or are you asking how to activate Colorbox for images that you insert with the inline module?

Anonymous’s picture

Yeah, inline has integration with any module defined formatters, in branch 7.x-2.x, i can write something like:


This is my first paragraph

[field|type=node|id=0|name=field_image|formatter=colorbox]

This is my second paragraph

Inline renders the field_image contents of the very same node (id=0, in this example) between the first and second paragraphs.

So, i think looking at the colorbox code, i've found i have no option to render just one specific element. The code is at:

http://drupalcode.org/project/colorbox.git/blob/a7239f421e520ccd0ce333b1...

>

/**
 * Implements hook_field_formatter_view().
 */
function colorbox_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();

  foreach ($items as $delta => $item) {
    $element[$delta] = array(
      '#theme' => 'colorbox_image_formatter',
      '#item' => $item,
      '#entity_type' => $entity_type,
      '#entity' => $entity,
      '#node' => $entity, // Left for legacy support.
      '#field' => $field,
      '#display_settings' => $display['settings'],
    );
  }

  return $element;
}
<

Thise code simply does a foreach for each field element, so i have no option to render just one specific array element.

I hope u understand now. May be somebody can think of a solution to this? I'm thinking of a special value on the $display['settings'] which can be used for limiting the foreach?

Anonymous’s picture

Component: Miscellaneous » Code
Status: Active » Needs review
FileSize
3.23 KB

My patch adding a display setting for handling multi valued fields. Hope can be reviewed and applied upstream. Cheers!

frjo’s picture

Can you then insert formatter options via the inline tags?

This seems to be a quite special case so I'm hesitant to clutter the UI. I could add "hidden" settings that you can activate by inserting formatter option via other modules.

On the few occasions when I needed this kind of functionality I have used the Insert module. I have added integration with it in the Colorbox module.

http://drupal.org/project/insert

Anonymous’s picture

Yeah, i can add formatter settings on the inline tags (using it right now).

I've implemented the UI part thinking on the usability for non-inline advanced users, also for making it a "standard feature" of colorbox module. But if u can add this without the UI part, great for my use case anyway! Your decision :)

frjo’s picture

Would something like this work for you?

Anonymous’s picture

Absolutly! Please push to master. Thanks.

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community
frjo’s picture

Assigned: Unassigned » frjo
Category: support » feature
Status: Reviewed & tested by the community » Fixed

Committed to 7.x-2.x-dev.

Status: Fixed » Closed (fixed)

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