Hi there,
After upgrading to the latest version (7.x-2.11) I noticed that the alt and title text for my image field (not a "Media" field) is no longer displayed. After a bit of debugging I figured that the values are still available in table field_data_field_image but seem to be overridden by field_file_image_alt_text and field_file_image_title_text respectively. Needless to say that these values for my ordinary image field are empty and thus the displaying of alt and title texts are empty too.
This all happens in function file_entity_set_title_alt_properties() (file_entity.file.inc) which is being called by file_entity_set_title_alt_properties_on_file_fields() originating in file_entity_entity_load(). These 2 functions have been added in the release mentioned above.
As the logic to detect if it's a file/image/something field (in file_entity_set_title_alt_properties_on_file_fields()) is alike between media field and ordinary image field I tried to intercept at a deeper level. Here's the code which overrides the file's alt and title text:
foreach ($files as $file) {
// Load alt and title text from fields.
if (!empty($alt)) {
$output = token_replace($alt, array('file' => $file), $replace_options);
// @todo Remove once https://www.drupal.org/node/1713164 is fixed.
// There is currently no way to get the raw alt text returned from the
// token so we revert the encoding done during tokenization.
$file->alt = decode_entities($output);
}
if (!empty($title)) {
$output = token_replace($title, array('file' => $file), $replace_options);
// @todo Remove once https://www.drupal.org/node/1713164 is fixed.
// There is currently no way to get the raw title text returned from the
// token so we revert the encoding done during tokenization.
$file->title = decode_entities($output);
}
}
By checking if $output is empty (or rather not) and only then overriding the original alt/title text it seems to do the trick. Like this:
// Load alt and title text from fields.
if (!empty($alt)) {
$output = token_replace($alt, array('file' => $file), $replace_options);
if (!empty($output)) {
// @todo Remove once https://www.drupal.org/node/1713164 is fixed.
// There is currently no way to get the raw alt text returned from the
// token so we revert the encoding done during tokenization.
$file->alt = decode_entities($output);
}
}
Comment | File | Size | Author |
---|---|---|---|
#2 | file_entity-keep_original_alt_title_text-2918049-1.patch | 1.6 KB | sitiveni |
Comments
Comment #2
sitiveni CreditAttribution: sitiveni commentedComment #3
joseph.olstadis this a new issue or an older one?
When did you first notice this? with which tagged release?
see this possibly related issue or the other possibly related issues that are linked to the following issue.
#2665960: Image Alt and Title displayed in the wrong language IF field format is not "rendered file"
Comment #4
jerry CreditAttribution: jerry commentedI started seeing this problem as well as of 7.x-2.11 (I think) on an older site which uses ImageField Tokens. The patch in #2 appears to have resolved the problem here. (Thanks, sitiveni.)
Comment #5
steveoriolThe patch in #2 appears to have resolved the problem too.
Thank you sitiveni.
Comment #8
joseph.olstadComment #9
joseph.olstadreviewed patch, seems reasonable and fairly low risk.
thanks for the reviewers feedback as well.
fixed in 7.x-2.x dev and 7.x-3.x dev
Comment #10
bradallenfisher CreditAttribution: bradallenfisher commentedThe dev version works.
Comment #11
donaldwbabcock CreditAttribution: donaldwbabcock commentedCan confirm that this works.
Any way to get this rolled as 7.x-2.12?
Comment #12
joseph.olstadwhat's this ?
#2919383: ALT and TITLE tag conflict between Field Storage and File Entity Storage
related issue?
Comment #13
donaldwbabcock CreditAttribution: donaldwbabcock commentedJoseph, "This" is the patch in #2 against 7.x-2.x, which was committed to dev on Oct 24, 2017. The issue in #2919383: ALT and TITLE tag conflict between Field Storage and File Entity Storage is separate and more complex. As best I can tell, the patch as committed gets us back to the behavior before it broke.
Comment #14
Ambient.ImpactCan also confirm that 7.x-2.x fixes this. Was worried for a bit that the data might have been lost. Thanks!
Comment #15
joseph.olstadI'm holding off a release of this fix due to the observations in #2919383: ALT and TITLE tag conflict between Field Storage and File Entity Storage
If you want to help out, please follow up in:
#2919383: ALT and TITLE tag conflict between Field Storage and File Entity Storage
Comment #16
Yazzbe CreditAttribution: Yazzbe commentedI seem to have lost some ALT & TITLE tranlations on a multi lingual website. Probably overridden. The latest dev version didn't bring those back.
My website uses a standard image file field, with alt and title field enabled in the node edit form (not the media widget).
edit: reverted back to 7.x-2.8 on a live site to get the previous multilingual behaviour back.
Comment #17
fsignoret CreditAttribution: fsignoret commentedThank you for the fix on 7.x-2x!
The release of this fix should be considered as urgent: in case you have several images and you save one change in the form, data is lost...
Hopefully I could manually get my data from a database backup.
Comment #18
joseph.olstadThe reported issues here are confusing because I haven't noticed them.
However the commit looks pretty safe.
Comment #19
joseph.olstadOk, after several reports of success, and I myself tested it (I didn't notice a change before or after) I've tagged a new release . 7.x-2.12.
to me this commit has no effect either way. Maybe because my site is multilingual with the latest entity_translation and latest media module, not sure.
Comment #20
dat deaf drupaler CreditAttribution: dat deaf drupaler as a volunteer commentedConfirmed this patch and updating to 7.x-2.12 solve this problem.. thank you @sitiveni for quick catch and posting patch! You saved my day!
@fsignoret: data was not lost as they were still in the database, it was refusing to save new entries when original img tags disappeared however upon updating to 2.12 all data came back, thank god.
Comment #21
fsignoret CreditAttribution: fsignoret commented@dat deaf dupaler: in my case, it did not refuse to save.
Comment #22
Yazzbe CreditAttribution: Yazzbe commentedI was not so lucky. Updating to 7.x-2.12 does not show the translated alt & title values form the file widget like in 7.x-2.8 on my site.
It shows the alt & titles value in 1 language across all pages.
Comment #23
joseph.olstad@yazzybe, I have multilingual and all alt and title values are showing up in the right language on my system. I suggest possibly a cache clear
if that doesn't work, try running the 'hacked' module to see what modules might be altered (patched) or just plain hacked in your filesystem.
also, to diagnose your system, run the dmf module to see if you've got duplicate module files in your filesystem
https://www.drupal.org/project/dmf
Also check the status report, and make sure to run update.php (or drush updb) if you haven't already.
Also make sure that if you're using the entity_translation module that you have the latest release. the latest release of entity_translation is 7.x-1.0-beta7, this is what we're using and it's working nicely for us.
Comment #25
joseph.olstadDo you have the "token" module enabled? If "token" is not enabled the alt and title text will not appear. I think the solution here is to first upgrade file_entity to latest version and then enable the "Token" module. The alt and title text are now tokens in the latest version. The token module should probably be a required dependency. However most people already have this module enabled.
Comment #26
Yazzbe CreditAttribution: Yazzbe commentedYes, token was enabled.
Entity Translation 7.x-1.0-beta7, cc all, updb, no hacked or patched modules.
still on file entity 2.8 though.
Comment #27
joseph.olstadare you using the entity cache module? any other caching modules? are you using memcache or some other type of php caching ? what version of php?
I am on php 7.0.22
no memcache here.
Comment #28
joseph.olstadA-ha , yes that explains it, you need to upgrade file_entity to version 2.12
David Rothstein (one of the Drupal 7 core maintainers) wrote a few fixes to the alt and title logic and it is included in 2.12
Comment #29
joseph.olstadupgrading to file entity 2.12 should fix this.
Let me know. Thanks
Comment #30
sherkajon CreditAttribution: sherkajon commentedDears,
I need your help, couple of days ago I have upgraded into Drupal 7.58 and updated all modules to the latest versions.
Now i'm facing a problem with Image Field. It is not keeping ALT and TITLE values on node creation and updating.
File Entity module: Version: 7.x-2.18
Token module: Version: 7.x-1.7
Entity Tokens module: Version: 7.x-1.9
Appreciate your recommendations.
Thank you.
Comment #31
perpignan CreditAttribution: perpignan commented+1 , same issue with File Entity module: Version: 7.x-2.18 no alt and title for the file field.
Comment #32
sherkajon CreditAttribution: sherkajon commentedperpignan,
I fixed it this way on file_entity.file.inc line number 273 (function file_entity_set_title_alt_properties):
Instead of:
I put:
and it worked for me.
Comment #33
web226 CreditAttribution: web226 commentedThank you @sherkajon your solution fixed it for me with File Entity 7.x-2.17+1-dev. Is anyone able to roll this solution into a patch?
Comment #34
joseph.olstadThe ones that have issues here, are you using mysql for a database driver and database system? or PostgreSQL or sqlsrv ?
or some other system?
what version of php
any other contrib modules not up to date?
Note file_entity 7.x-2.19 has been tagged and released with performance improvements over 2.17 and also some edge case bug fixes.
Comment #35
sherkajon CreditAttribution: sherkajon commented@joseph.olstad ,
All my dependent modules are up to date. I'm using MySQL (MariaDB) as a database server and PHP 5.6.35.
Comment #36
maki3000 CreditAttribution: maki3000 commented+1 I have the same settings as sherkajon
Comment #37
perpignan CreditAttribution: perpignan commentedThank you @sherkajon ! it works on 7.x-2.17
I updated File entity to 7.x-2.19, it's not fix on this version !!! When i apply the patch on 7.x-2.19, it works.
I hope, on next version ( 2.20 ) it will be integrated !
Comment #38
joseph.olstadI'm looking into this. possible related issue as described in this issue summary.perhaps affects those not using the entity module.
#1713164: field_tokens() isn't respecting sanitize option
Comment #39
joseph.olstadeveryone here, if you run this drush command, what is the result?
drush vget file_entity_title
if the result is:
file_entity_title: '[file:field_file_image_title_text]'
then in version 7.x-2.19 file_entity.module the following code block gets processed:
otherwise:
none of the suggestions above would apply to 7.x-2.19
I was unable to make any patch using the suggestions above. In fact the comments seem to illustrate perhaps accidental errors on the part of the authors writing incomplete or half baked comments.
Comment #40
joseph.olstadif someone can shed some light here, provide guidance, that'd be appreciated. It seems there's an opportunity for improvement here because several reports here.
Comment #41
joseph.olstadThe changes were made to file_entity by David Rothstein and some other high profile Druaplistas, important changes were made to the handling of alt and title due to performance reasons and to perfect multilingual alt and title field accuracy.
I also worked on the related issues and had previously came up with a core patch, but that core patch should no longer be needed due to the fix by David Rothstein. It's better to fix things in contrib than core, only when absolutely necessary to patch core.
For those people still experiencing issues with this, it could be due to a number of factors varying on setup and configuration.
What core patches are people using?
anyone have make files that contain up-to-date versions and list of modules and patches and core version?
Comment #42
ABaier CreditAttribution: ABaier commentedWe are experiencing the same issue. In our case the regular image titles (core image fields) are not printed anymore and the node edit form shows empty fields.
The previous values are still present in the database but get overridden, empty or with new input, if the node form is saved. This seems critical to me, because the form still shows empty fields if you load it again, but things were saved in the background.
All modules and core are up to date and we recently updated file_entity to 7.x.2.19 (before 7.x.2.17 and 7.x.2.18). Unfortunately I don't know which version caused this behavior.
Drupal core 7.58 (no patches, single language installation)
Memcache 3.0.9-dev
PHP 7.0.27
Comment #43
Arm77 CreditAttribution: Arm77 commentedDowngrade to 7.x-2.17 fixed the problem. I use ImageField Tokens 7.x-1.x-dev. with the token [node:title] for both Alt and Title field. in File Entity configuration 7.x-2.17 I leave Alt & Title attribute as Blanks and everything else unchecked. everything works fine until I upgraded to 7.x-2.19. (I guess the problem starts in 7.x-2.18).
Comment #44
joseph.olstadok, use 7.x-2.17 if this affects you, hopefully figure out the regression quickly and fix it.
Comment #45
joseph.olstadLikely that the regression is caused by #2642764: Speed up via shortcutting token file_entity_file_load
Comment #46
joseph.olstadok, 7.x-2.20 was released
I backed off 2642764
let us know if there's still an issue with 7.x-2.20
based on reports, it should work like 7.x-2.17 does
knock on wood
Comment #47
Kniekel CreditAttribution: Kniekel commentedThank you! I installed the new version 7.x.2.20 and everything seems to work ok.
Comment #48
joseph.olstadthanks for reporting
Comment #49
Arm77 CreditAttribution: Arm77 commentedThanks, 7.x.2.20 works.
Comment #50
perpignan CreditAttribution: perpignan commentedThank you ! 7.x-2.20 works for me too :-)
Comment #51
sherkajon CreditAttribution: sherkajon commentedThank you! 7.x-2.20 also works well for me!
Good job, Joseph.
Comment #52
joseph.olstadThanks to Arm77 for reporting his findings, led to a quick solution! cheers
Comment #53
mtoscano CreditAttribution: mtoscano commentedFixed, thanks.
Comment #55
IckZ CreditAttribution: IckZ commentedHey,
there seems to be still a bug in the module. If the entity has an alt and a title tag it does not update the title or alt tag if I edit it by node/edit.. I can only edit the tags if i go directly to /file/../edit/
If I disbale the line
//$file->alt = decode_entities($output);
from the patch the alt tag gets updated. But this cant be the right solution. What do you mean?Comment #56
l-laziz CreditAttribution: l-laziz commentedI second IckZ's #55 comment. The issue still persists. Can't save alt text/title via node/edit. Can save it though via file/edit.
Comment #57
joseph.olstadfollow up here:
#3145805: Image Alt Text and Title can't be saved on node/edit unless using the form dialog provided by the file 'edit' button.