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.
Hi.
How can i add alt and title fields for default images?
Thank you
Comment | File | Size | Author |
---|---|---|---|
#39 | default_image_w_h.patch | 724 bytes | niko- |
#36 | default_image_w_h.patch | 704 bytes | niko- |
Comments
Comment #1
LTech CreditAttribution: LTech commenteddid you find a solution?
I would like to set alt to the node title for a default image, so when you hover over the image you see the node title.
How do I do this?
Comment #2
eojthebraveCurrently you can't do this using the core image module in Drupal 7. You might possibly be able to find a contrib module that adds this functionality or use something like
hook_field_info_alter()
to add this option the settings for the image field widget.This does seem like a useful feature to have though so moving to D8 and changing to a feature request.
Comment #3
claudiu.cristeaComment #4
claudiu.cristea#1769428: Add title and alt 'fields' for default images of an Image Field. is duplicating this.
Comment #5
claudiu.cristeaFixing status.
Comment #6
claudiu.cristeaHere's a first patch.
Comment #8
claudiu.cristeaForgot about user picture upgrade path.
Comment #9
claudiu.cristeaThis patch no longer applies and had to be reworked in top of other changes to filed settings. Hard to obtain an interdiff. There's a single change: default image setting fid is casted to integer in annotation and profile YAML.
Comment #11
claudiu.cristeaUps! There were an upload error and has uploaded twice. Cancelled one test.
Comment #12
claudiu.cristeaLet's see
Comment #13
claudiu.cristea#1392416: Dimensions not rendered on fields with default image is about the same default image but is handling the lack of 'width' and 'height' in
<img />
. While in this patch we are changing the field and instance 'default_image' setting from integer to array it would be great if we can store in the newdefault_image
array also the width and the height of the default image. That is needed to cache the dimensions and reuse that information (see @catch comment #1392416-16: Dimensions not rendered on fields with default image).Because it became more easy to handle here also the dimensions stuff, in the same patch, let's merge here the 2 issues. Closing #1392416: Dimensions not rendered on fields with default image as duplicate and renaming this issue.
Comment #14
claudiu.cristeaHere's a patch with #1392416: Dimensions not rendered on fields with default image merged.
Comment #16
claudiu.cristeaCancelled the test from #14 because I found that I left the config factory injection but we don't need it anymore.
Comment #18
eojthebraveThis is a great idea and the patch is coming along really well. I haven't tried applying it yet but based on a quick read of the most recent patch here's a couple of comments.
This comment seems a little vague. Might be better to have it say something like, "Add alt, title, width, and height options to image field 'default_image' setting."
"... default image save the with ...", you can probably remove the word "get" from this sentence.
I'm not sure the "Code reusing in ..." line is really necessary here and having it means you would also need to update that line anytime the function is used somewhere else. Combine that with the fact that api.drupal.org will already figure out usages for you I think we can remove it.
And, if this is form array and not an individual element should we call it $form instead?
I think the text here should read ", and when" not ", or when" making it consistent with other instances in core.
Lets make this one consistent with image widgets in core and make it:
'The title attribute is used as a tooltip when the mouse hovers over the image.'
Keep up the awesome work!
Comment #19
claudiu.cristeaVoilà!
Comment #21
claudiu.cristeaRerolled.
Comment #23
claudiu.cristeaOK, crossed the upgrade path jungle again, I'm alive :)
Comment #24
swentel CreditAttribution: swentel commentedTwo quick questions:
Wondering whether we should check that $uri and/or $image is actually a valid result or not.
'Ensure sure' sounds really weird - although it was there already originally. However, won't this now be an array by default anyway ?
Other than that, this is really solid. Tested it manually as well and works fine.
Comment #25
claudiu.cristeaYou're right in both. Let's see this one.
Comment #26
swentel CreditAttribution: swentel commentedGreat, good to go for me.
Comment #27
alexpott25: alt-title-dim-default-img-1443606-25.patch queued for re-testing.
Comment #29
claudiu.cristeaThe retest failed because of the bot (see logs). I manually requested a re-test on qa.drupal.org and passed. So switching back to RTBC.
Comment #30
alexpottCommitted 9008a59 and pushed to 8.x. Thanks!
Comment #31
claudiu.cristeaHere's the change notice: https://drupal.org/node/2142533.
Comment #32
claudiu.cristeaForgot the title.
Comment #33
claudiu.cristeaComment #34
jibranI think we should backport this patch.
Comment #35
claudiu.cristea@jibran, right this deserves a backport. Unfortunately we don't have a presave or something similar in order to process the width and height of the default image when saving field/instance settings. In Drupal 8 we are simply using
hook_entity_presave()
but that is not the clean way.I discussed this issue with @yched today, at Drupalcamp Vienna, and we've decided to open #2143019: Allow field type to specify a 'process settings' step before saving & loading definitions which will be backported to D7 too. So this will be handled after that is backported. Postponing this till #2143019: Allow field type to specify a 'process settings' step before saving & loading definitions.
Comment #36
niko- CreditAttribution: niko- commentedHi,
Backport to D7 attached. Not sure if some tests needed.
Comment #37
andypostseems no reason to postpone, this kind of fix makes sense except the file is not remote
Comment #39
niko- CreditAttribution: niko- commentedfixed #36 patch
Comment #41
claudiu.cristeaBug after 8.x commit: #2226241: Saving image field or instance with an inexistent default_image crashes.