Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have created a custom formatter with the following code:
<div class="image-with-caption">
<div class="image"><img src="[site-url]/[filefield-imagecache-square-thumbnail]" alt="[filefield-alt]" title="[filefield-title]" /></div>
<div class="caption-box"><span="caption"><a href="[site-url]/node/[node-nid]">Description: [field_image-filefield-description] Size: [field_image-filefield-filesize_formatted]</a></span></div>
</div>
when using insert to insert an image with the above formatter, it will render into the following:
<div class="image-with-caption">
<div class="image"><img src="http://www.example.com:8080/sites/www.example.com/files/imagecache/square-thumbnail/Albert_Einstein_Head_Cleaned_N_Cropped.jpg" alt="" title="" width="90" height="90"/></div>
<div class="caption-box"><span="caption"><a href="http://www.example.com:8080/node/1">Description: Albert Einstein Description Size: 585.14 KB</a></span="caption"></div>
</div></div>
The code changes some of the tokens, but not all. I have inserted the same code through insert and it is able to format the above two missing tokens correctly. Though it has a similar problem with the alt and title tokens.
As the example shows, the alt and title tags are not rendered; the same happens if I change those tags to [field_image-filefield-alt] and [field_image-filefield-title]
Comments
Comment #1
boclodoa CreditAttribution: boclodoa commentedAfter some headaches here is my solution:
use an advanced custom formatter with the following code
How did I get here? using the "convert" option of the custom formatter over the formatter posted by pkej, and then analyzing the output of an other (advanced) custom formatter with the code
I've notice two things:
1 - the $element array does not have the same content if you call it trough the insert module, or trough the cck "display fields", or through the the linodef module.
2 - the $element['#item']['data'] is empty when you call it through the linodef module.
WARNING: this code will give you a server error if you don't change the name of my imagefield (field_imagen) with yours, and the name of my imagecache preset (thumbnail) with yours.
Comment #2
boclodoa CreditAttribution: boclodoa commentedan other example with more details
Comment #3
pkej CreditAttribution: pkej commentedThank you very much for your time and effort. I will use it for future reference on my upcoming play time with D7 :)