Image in View with Lightbox2 formatter lacking alternative text tag I have a page view for image gallery. It has only 1 Photo field of Photo which has a field of type Image. In view it use "Lightbox2: lightshow: small-square -> large" as formatter. small-square is a custom image style.

The rendered page doesn't show any alt tag:

&lt;img typeof="foaf:Image" src="http://www.example.com/sites/default/files/styles/small-square/public/6486388587_61846b6d84_1323732945.jpg" width="240" height="240"&gt;


I need to add alt tag to images. What do I have to change?

My drupal installation has these versions:


Drupal 7.10
Lightbox2 7.x-1.0-beta1
Views 7.x-3.0-rc3


looking at Lightbox2 modules's file lightbox2.formatter.inc it seems that alt tab should be forced to show, using image title.

  // Set up the title.
  $image_title = $item_data['description'];
  $image_title = (!empty($image_title) ? $image_title : $item_data['title']);
  $image_title = (!empty($image_title) ? $image_title : $item_data['alt']);
  if (empty($image_title) || variable_get('lightbox2_imagefield_use_node_title', FALSE)) {
    $node = node_load($node-&gt;nid);
    $image_title = $node-&gt;title;
  }

  $image_tag_title = '';
  if (!empty($item_data['title'])) {
    $image_tag_title = $item_data['title'];
  }


  // Enforce image alt.
  if (!empty($item_data['alt'])) {
    $image_tag_alt = $item_data['alt'];
  }
  elseif (!empty($image_title)) {
    $image_tag_alt = $image_title;
  }  $image_tag_alt = '';
  if (!empty($item_data['alt'])) {
    $image_tag_alt = $item_data['alt'];
  }
  elseif (!empty($image_title)) {
    $image_tag_alt = $image_title;
  }


So... where is the error?
For people coming to this page...I wanted to use the title of the node containing the image as the caption on the lightbox2 image, which I was displaying in a view, but I didn't want to modify the module, which I think is the issue with the above technique.

What I ended up doing was making my own image formatter.  Basically I cut and pasted the hook_field_formatter_info and hook_field_formatter_view from the lightbox2 module and modified them.   There may be a better way, but it works, solved my problem, and I can upgrade lightbox2 without worrying about breaking my site.

/**
 * Implementation of hook_field_formatter_info().
 */
function mymod_field_formatter_info() {
  $formatters = array();
  if (module_exists('image')) {
    $formatters["mymod_custom_formatter"] = array( 
      "label" =&gt; "Field formatter for my Photos",
      "field types" =&gt; array("image"),
    );
  }
  return $formatters;
}

/**
 * Implements hook_field_formatter_view().
 */
function mymod_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $pieces = explode('__', "lightbox2__lightbox__thumbnail__large"); // forced this, you could do something trickier, but it solved my issue

  ... untouched ...
  foreach ($items as $delta =&gt; $item) {
    // here is the bit I added which sets the node title to be the image caption
    if ($entity_type == 'node') {
      $item["title"] = $entity-&gt;title;
    }

    $uri = array(
    ... etc ...