Hi.

I tried to create the submodule wysiwyg_imageupload_caption.

With the caption is possible to have a title and a caption with two distinct field. The caption is used as legend and the title is used for the alt and title attributes for tag img.
The first time the submodule is activated, it creates a new column "caption" in table "wysiwyg_imageupload_entity" and copies all records of column "title" in that new column.
This way, if you activate this submodule for the first time, all seems the same. Every image have its caption as before (if you have entered a title).

From now you can change the caption (in the Extras section).

See the attached zip file.

It also requires a change in file wysiwyg_imageupload.module

/**
 * Renders the meta data of an image. By default only the title
 */
function theme_wysiwyg_imageupload_render_meta($img_obj, $arguments) {
  $output = '';
  //Return TRUE if the module is both installed and enabled.
  if (module_exists('wysiwyg_imageupload_caption')) {
    if ($img_obj->caption != '') {
      $output .= "<span class='image_title'>{$img_obj->caption}</span>";
    }
  } else {
    if ($img_obj->title != '') {
      $output .= "<span class='image_title'>{$img_obj->title}</span>";
    }
  }
  return $output;
}

Can anyone test it?

Comments

eugenmayer’s picture

Wonderful addition!!! Thank you once again eletre!

I will have a look at both and include it in 2.10

eugenmayer’s picture

You can simply reimplement the theme method instead changing the core method?

eletre’s picture

maybe no.
First in a submodule I can't use MYSUBMODULE_wysiwyg_imageupload_render_meta($img_obj,$arguments).
Only in MYTHEME i can use MYTHEME_wysiwyg_imageupload_render_meta($img_obj,$arguments)

If, in my template.php of my theme I use this function it is called

function garland_wysiwyg_imageupload_render_meta($img_obj,$arguments){
 $output = '';
  //Return TRUE if the module is both installed and enabled.
 if (module_exists('wysiwyg_imageupload_caption')) {
    if ($img_obj->caption != '') {
      $output .= "<span class='image_title'>{$img_obj->caption}</span>";
    }
  } else { 
    if ($img_obj->title != '') {
      $output .= "<span class='image_title'>{$img_obj->title}</span>";
    }
  }
  return $output;
}

But function wysiwyg_imageupload_caption_wysiwyg_imageupload_render_meta($img_obj,$arguments) in wysiwyg_imageupload_caption.module is never called.

So, if we want the submodule independent of the theme, we have to modify the core module.
In addition, the title has the function of caption (if caption submodule is disabled), but the title loses its function of caption when the caption submodule is enabled.

I don't see another way.

If you know another way let me know.

eugenmayer’s picture

Ah, well i will give you a small snippet. Drupal CORE theme API is not supporting overriding of the theme methods in modules. But you can use the hook_theme_registry_alter hook to deal with that and extend it

eletre’s picture

StatusFileSize
new1.98 KB

Here is the new version without changes to the core.

Let me know.

eugenmayer’s picture

That looks good!

bohz’s picture

HI!
Testing this sub-module here.
It works OK, although when the caption has much text it stretches to the width of the content container.
I'd like to suggest to apply a width to the caption matching the width of the imagecache preset used for the image.
I will try to do it myself, but I am not a coder so any hint would be very welcome.

Thanks!

[EDIT]
I have solved the width problem adding the preset name as CSS class to the image title span tag;
I also forgot to mention that 255 chars might be insufficient for a caption, so I also suggest to change the data type of the caption field to someting larger than varchar. I tried with text, normal, and it works good so far.

ezra’s picture

Thanks, this module worked perfectly for me. I scanned all the source code and it looks like it's solidly written and certainly doesn't do anything nasty.

eugenmayer’s picture

Status: Needs review » Patch (to be ported)

Thanks, so i guess we can go forward here for the next release

eugenmayer’s picture

Status: Patch (to be ported) » Fixed

Status: Fixed » Closed (fixed)

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