The screencast shows that per image it is possible to have a title and description. However with D7 I don't get that option. Did I miss something that needs to be set up?

CommentFileSizeAuthor
#9 edit.jpg86.34 KBsharif.tanveer
#9 no title.jpg57.16 KBsharif.tanveer

Comments

DRIVE’s picture

Nope.

You can have title and alt on the image, image field does not support description (Drupal core). If Galleryformatter finds title, it will use it, if it finds only alt, it uses that.... if it finds neither, it uses node title.

    // Check if alt attribute is already set, if not use the filename as alt attribute
    $renderitems['slides'][$delta]['alt'] = (isset($item['alt']) && !empty($item['alt'])) ? $item['alt'] : $item['filename'];
    $item['alt'] = $renderitems['slides'][$delta]['alt'];

    // If the title is empty use alt or the node title in that order.
    if (empty($item['title'])) {
      if (!empty($item['alt'])) {
        $item['title'] = $item['alt'];
      }
      else {
        if(!empty($entity->title)){
          $item['title'] = $entity->title;
        }
        // if we have more than one image, add the image count to the title so they are not all the same.
        $item['title'] = ($num_of_images > 1) ? $item['title'] . t(' image ') . ($delta + 1) : $item['title'];
      }
    }

PS - alt should be mainly used for semantics; eg, xhtml requires alt on all images regardless of size to validate. alt can be empte (alt="") but is has to be there. General rule is use alt for text to display incase of 1) image not found, 2) user has images turned off in browser

tneo’s picture

Ah thanks. Which file do I need to edit?
(all new to Drupal and finding my way around).

DRIVE’s picture

You dont edit any files.... in your content type for the image field make sure to enable title and ALT and description... then just fill them in as you add images to your gallery.

Galleryformatter graciously uses the file name for ALT if you leave it blank but it is probably a good idea to fill it in with a truncated version of your description... or you can be like me... lazy :) I put my "titles" in the ALT since it is listed first as form input, then I copy and paste it to title :D... if you are fast and good with your keyboard you dont even need your mouse.... badda bing badda KABOOM!!

*oops :) Not description, alt and title sorry

tneo’s picture

Status: Active » Closed (works as designed)

Ah. Thanks. Solved. :-)

dellis’s picture

Status: Closed (works as designed) » Active

Sorry, quick clarification question. How can I get both the title AND the alt tag to display (as in your demo example)? for some reason, even though both alt and title are enabled for the imagefield, only the title is showing up?

DRIVE’s picture

* Demo example and screencast were from *Drupal 6* not D7 outdated

D7 image field does not have "description" as it shouldn't. The "img" tag "description" attribute is not valid, which is why Drupal removed it.

See the code block above. Read the comments.... self explanatory.

Now, since both alt will always exist because GF inserts filename if it is blank that leaves only the title to add a function to insert "something" into it if left blank. Therefore, it would be relatively easy to modify the caption output to behave similarly to the D6 version.

*modification of galleryformatter.module to include alt + title in captions not covered here (since we havent proposed code yet)

So the output to galleryformatter.tpl.php would end up being something like this... obviously a very crude example just for demo purposes:

      <?php foreach ($slides as $id => $data): ?>
        <li class="gallery-slide" id="<?php print $data['hash_id']; ?>">
          <?php print $data['image']; ?>
          <?php if (!empty($data['title']) && !empty($data['alt'])): ?>
            <div class="panel-overlay">
              <div class="overlay-inner">
                <?php if ($data['title']): ?><h2 or whatever tag><?php print $data['alt']; ?></h3 or whatever tag><?php endif; ?>
                <?php if ($data['title']): ?><h3><?php print $data['title']; ?></h3><?php endif; ?>
              </div>
            </div>
          <?php endif; ?>
        </li>
      <?php endforeach; ?>

Probably settings would be desired in case users dont want alt + title... Maybe only one or the other.... it's a dogfight! j/k
And of course any necessary tweaks to the panel-overlay and overlay-inner as/if required.

Therefore a patch is needed starting with galleryformatter.module.... Manuel requested that we use a different post specifically for that if we are going down that road. Are any of you guys experienced with PHP... or does that leave me or Manuel to start the process? :D Manuel has a new baby and works a high-power job so that leaves "us" for the time being and him to review patches which takes less time than writing them (lol... depending on whom you ax!) :D

dellis’s picture

Many thanks for the clarification. I see your point about adding complexity to the overlay, etc. I hadn't caught that the demo was D6--I clicked on "Try out a demonstration", now I see the demo link in the descriptor. Thanks for your help.

DRIVE’s picture

Category: support » feature
Priority: Normal » Minor
Status: Active » Closed (works as designed)
sharif.tanveer’s picture

Title: How to add title/ description to image » Whats about the default Gallery Content type ??
StatusFileSize
new57.16 KB
new86.34 KB

Hi, I have an issue at https://drupal.org/node/1951850 about this. you will find some screen-shot that might clear things a bit.

I think you guys are talking about creating a new type content and then add image field and enable alt and title field for the image, that's it. But I don't see any image field in the default Gallery type content field settings. But, once you create a gallery and upload images to it, it will allow you to edit media files & enter title, descriptions on it. I am writing there, but nothing showed up! Here some more screen-shot of Default Gallery type contents edit page and the display page of that gallery.

I must missing something, but I don't know perhaps the exact url to set those things even.

Thanks a lots for helping me around

-
Tanveer