Captions are not being added when images are inserted via the Insert module

Steps to recreate:

1. Install Drupal 7.14 using the "standard" install.
2. Install Insert 7.x-1.1 and Caption Filter 7.x-1.2
2. Go to Configuration > Test Formats > Filtered HTML, enable "Convert [caption] tags and allow image alignment"
3. Go to Configuration > Test Formats > Full HTML, enable "Convert [caption] tags and allow image alignment"
4. Go to Structure > Content Types > Article > Manage Fields
5. Under "Image" choose "Edit" from the "Operations" column
6. Click "Enable Title field"
7. Expand the "Insert" menu and check "Use the Title field as a caption" and "Enable insert button"
8. Go to "Add Content" and choose "Article".
9. Add a Title and Body content. Put the cursor where you want to insert the photo.
10. Under image click the [Choose File] button and select a file for uploading. Once done, click the [Upload] button.
11. Add "Alternate Text" text and "Caption" text.
12. Click the [Insert] button next to the image.
13. The image is inserted into the Body text, but the caption is not.

Closer examination reveals that only the HTML code for the image was added; the bracketed caption code was not. e.g.:

<img src="http://bar.foo.com/sites/default/files/field/image/nebula_rcw49_04lrg_0.jpeg" width="1152" height="907" alt="Here's my alt text" title="Here's my caption text" />

I then tested to make sure that the Caption Filter was working by adding some bracketed caption text. It worked just fine on its own. I installed the devel module and turned on error reporting, but I'm not seeing any errors, nor am I seeing any JavaScript errors in the Chrome developer console.

I ran these tests under Mac OS X 10.7 using Chrome 20.0.1132.47 and Firefox 13.0.1

Did I miss something? There was another report of a similar problem in this old issue for 6.x (http://drupal.org/node/1282078).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andreic’s picture

Subscribing, same issue here as the above. Any ideas someone?

technovangelist’s picture

Same issue here with 7.14 Minimal

minneapolisdan’s picture

I also was under the impression that this would just 'work' - that adding Title text to the image, and clicking Insert with the Insert module, the caption would be automatically placed, but so far I've had to type the caption out using the brackets.

Alan D.’s picture

Doesn't look like it, hook_insert_content() was not present in 7.x-1.2.

Super trivial if the author decides to implement this. I just hooked up the sandbox File Attributes module to do this (authorinfo is a textarea and author is a textfield on the image)

The sandbox project adds these additional tokens, just like insert does for title & alt, then I added the style like this:


/**
 * Implementation of hook_insert_styles().
 */
function momentum_insert_styles() {
  $insert_styles['momentum_author'] = array(
    'label' => t('Momentum author info'),
  );
  return $insert_styles;
}

/**
 * Implementation of hook_insert_content().
 */
function momentum_insert_content($item, $style, $widget) {
  $style_name = 'inline_author';

  $file = file_load($item['fid']);
  $uri = image_style_path($style_name, $file->uri);
  $url = insert_create_url($uri);
  $class = !empty($widget['settings']['insert_class']) ? $widget['settings']['insert_class'] : '';

  $image = '<img src="' . $url . '" alt="__alt__" title="__title__" class="image-' . $style_name . ($class ? ' ' . $class : '') . '" />';
  return "<div class=\"tan\">{$image}<h3>__file_attributes_author__</h3><p>__file_attributes_authorinfo__</p></div>";
}

so these bits, '__file_attributes_authorinfo__' would be __title__ or __alt__ and the styles would be:

function momentum_insert_styles() {
  $insert_styles['caption_filter_left'] = array(
    'label' => t('Caption filter left'),
  );
  $insert_styles['caption_filter_right'] = array(
    'label' => t('Caption filter right'),
  );
  // en_US is the "en" locale
  $insert_styles['caption_filter_center'] = array(
    'label' => t('Caption filter center'),
  );
  return $insert_styles;
}
Alan D.’s picture

Duh, I should have looked at the author first (quicksketch, also author of Insert) before pasting in help on how to do this :)

pam.pkrweb@gmail.com’s picture

Hi

I am having the same issue. Do the same step stated in the original summary on the issue. I get no Caption. Any patch to fix this.

shadcn’s picture

Here's a quick patch that adds image style + caption support.

siefca’s picture

I've included this patch in my patch, see: http://drupal.org/node/1873900

davidneedham’s picture

Status: Active » Needs review
kmonty’s picture

Version: 7.x-1.2 » 7.x-1.x-dev
Status: Needs review » Postponed (maintainer needs more info)

After some testing, it appears the captions are being inserted just fine (it's possible this issue was fixed along with another ticket).

There is an issue that causes captions to be inserted more often than desired. Please track #1985458: Problem with caption_from_title? for progress surrounding the clean-up of general caption insert functionality.