Support from Acquia helps fund testing for Drupal Acquia logo

Comments

LTech’s picture

did 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?

eojthebrave’s picture

Version: 7.12 » 8.x-dev
Category: support » feature

Currently 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.

claudiu.cristea’s picture

Title: Create alt field for default images » Alt and title for default images
Assigned: Unassigned » claudiu.cristea
Category: feature » task
Status: Active » Needs review
claudiu.cristea’s picture

claudiu.cristea’s picture

Status: Needs review » Needs work

Fixing status.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
23.89 KB

Here's a first patch.

Status: Needs review » Needs work

The last submitted patch, alt-title-default-img-1443606-6.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
1.26 KB
25.21 KB

Forgot about user picture upgrade path.

claudiu.cristea’s picture

This 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.

Status: Needs review » Needs work

The last submitted patch, alt-title-default-img-1443606-9.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review

Ups! There were an upload error and has uploaded twice. Cancelled one test.

claudiu.cristea’s picture

Let's see

claudiu.cristea’s picture

Title: Alt and title for default images » Alt, title, width and height of default images

#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 new default_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.

claudiu.cristea’s picture

Status: Needs review » Needs work

The last submitted patch, alt-title-dim-default-img-1443606-14.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
2.86 KB
27.14 KB

Cancelled the test from #14 because I found that I left the config factory injection but we don't need it anymore.

Status: Needs review » Needs work

The last submitted patch, alt-title-dim-default-img-1443606-16.patch, failed testing.

eojthebrave’s picture

This 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.

+++ b/core/modules/field/field.installundefined
@@ -579,7 +579,34 @@ function field_update_8006(&$sandbox) {
+/**
+ * Convert image field and instance setting 'default_image'.

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."

+++ b/core/modules/image/image.moduleundefined
@@ -417,12 +417,24 @@ function image_entity_presave(EntityInterface $entity, $type) {
+
+      // If there's a new default image get save the width and height in the
+      // field/instance settings.

"... default image save the with ...", you can probably remove the word "get" from this sentence.

+++ b/core/modules/image/lib/Drupal/image/Plugin/field/field_type/ImageItem.phpundefined
@@ -317,6 +320,58 @@ public static function validateResolution($element, &$form_state) {
   /**
+   * Builds the default_image details element.
+   *
+   * Code reusing in both, settingsForm() and instanceSettingsForm() methods.
+   *
+   * @param array $element
+   *   The form associative array passed by reference.
+   * @param array $settings
+   *   The field settings array.
+   */
+  protected function defaultImageForm(array &$element, array $settings) {

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?

+++ b/core/modules/image/lib/Drupal/image/Plugin/field/field_type/ImageItem.phpundefined
@@ -317,6 +320,58 @@ public static function validateResolution($element, &$form_state) {
+      '#description' => t('This text will be used by screen readers, search engines, or when the image cannot be loaded.'),

I think the text here should read ", and when" not ", or when" making it consistent with other instances in core.

+++ b/core/modules/image/lib/Drupal/image/Plugin/field/field_type/ImageItem.phpundefined
@@ -317,6 +320,58 @@ public static function validateResolution($element, &$form_state) {
+      '#description' => t('The title is used as a tool tip when the user hovers the mouse over the image.'),

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!

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
15.61 KB
32.53 KB

Voilà!

Status: Needs review » Needs work

The last submitted patch, alt-title-dim-default-img-1443606-19.patch, failed testing.

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
32.55 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, alt-title-dim-default-img-1443606-21.patch, failed testing.

claudiu.cristea’s picture

Title: Alt, title, width and height of default images » Alt, title, width and height for default images
Status: Needs work » Needs review
FileSize
32 KB
3.56 KB

OK, crossed the upgrade path jungle again, I'm alive :)

swentel’s picture

Two quick questions:

  1. +++ b/core/modules/image/image.install
    @@ -237,3 +248,36 @@ function image_update_8002() {
    +        $image = $image_factory->get($uri);
    +      }
    +      $default_image = array(
    +        'fid' => $fid ?: NULL,
    +        'alt' => '',
    +        'title' => '',
    +        'width' => $fid ? $image->getWidth() : NULL,
    +        'height' => $fid ? $image->getHeight() : NULL,
    

    Wondering whether we should check that $uri and/or $image is actually a valid result or not.

  2. +++ b/core/modules/image/image.module
    @@ -446,10 +463,10 @@ function image_field_entity_update(FieldInterface $field) {
    +  // Ensure sure that fid_new and old are arrays, because default_image might be
    

    '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.

claudiu.cristea’s picture

You're right in both. Let's see this one.

swentel’s picture

Status: Needs review » Reviewed & tested by the community

Great, good to go for me.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: alt-title-default-img-1443606-9.patch, failed testing.

claudiu.cristea’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community

The 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.

alexpott’s picture

Title: Alt, title, width and height for default images » Change notice: Alt, title, width and height for default images
Priority: Normal » Major
Status: Reviewed & tested by the community » Active
Issue tags: +Needs change record

Committed 9008a59 and pushed to 8.x. Thanks!

claudiu.cristea’s picture

Assigned: claudiu.cristea » Unassigned
Priority: Major » Normal
Issue tags: -Needs change record

Here's the change notice: https://drupal.org/node/2142533.

claudiu.cristea’s picture

Title: Change notice: Alt, title, width and height for default images » Alt, title, width and height for default images

Forgot the title.

claudiu.cristea’s picture

Status: Active » Fixed
jibran’s picture

Version: 8.x-dev » 7.x-dev
Status: Fixed » Patch (to be ported)
Issue tags: +Needs backport to 7.x

I think we should backport this patch.

claudiu.cristea’s picture

Status: Patch (to be ported) » Postponed

@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.

niko-’s picture

FileSize
704 bytes

Hi,

Backport to D7 attached. Not sure if some tests needed.

andypost’s picture

Status: Needs review » Needs work

The last submitted patch, 36: default_image_w_h.patch, failed testing.

niko-’s picture

Status: Needs work » Needs review
FileSize
724 bytes

fixed #36 patch

Status: Needs review » Needs work

The last submitted patch, 39: default_image_w_h.patch, failed testing.

claudiu.cristea’s picture

  • alexpott committed 9008a59 on 8.3.x
    Issue #1443606 by claudiu.cristea: Alt, title, width and height for...

  • alexpott committed 9008a59 on 8.3.x
    Issue #1443606 by claudiu.cristea: Alt, title, width and height for...

  • alexpott committed 9008a59 on 8.4.x
    Issue #1443606 by claudiu.cristea: Alt, title, width and height for...

  • alexpott committed 9008a59 on 8.4.x
    Issue #1443606 by claudiu.cristea: Alt, title, width and height for...