Environment:
- Media (latest dev)
- Entity Translation
- i18n
Trying to be as succinct as possible here:
'media_filter' calls 'media_token_to_markup' in order to convert the json array into markup. Everything works as expected when when you are using the interface to save your entities.
The problem occurs when you aren't using the interface to create entities. Perhaps using some tools such as Migrate, Feeds, UUID_Features and so on. Inside the function 'media_token_to_markup' the file_load function is called which in turns calls the entity_controller and media's own 'MediaEntityTranslationHandler'. The problem with this handler is that it only bases itself on the $global language. So say you are using migrate to bring in your entities the $global language will always be 'en' and file_load($fid) will only ever return the english alt value.
I have created a patch that does a few things:
- Converts function media_filter to full form so langcode of the field can be taken into account.
- Function media_token_to_markup takes the langcode parameters and passes it to:
- media_get_file_without_label
- field_attach_prepare_view
- entity_prepare_view
- field_attach_view
// Field Translation Support.
if (field_has_translation_handler('file')) {
$field_items = field_get_items('file', $file, 'field_file_image_alt_text', $langcode);
foreach ($field_items as $field_item) {
$element['#alt'] = $field_item['safe_value'];
}
}
I was wondering if all of this makes sense or there something I clearly missed that negates the need to do all of this?
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | media_alt_attributes-2129273-24.patch | 5.75 KB | sylus |
| #23 | media_alt_attributes_et_2129273-23.patch | 5.13 KB | letrotteur |
| #20 | media_alt_attributes_et-2129273-20.patch | 4.81 KB | sylus |
Comments
Comment #1
sylus commentedComment #2
sylus commentedComment #3
sylus commentedComment #4
sylus commentedComment #5
sylus commentedMinor styling adjustments.
Comment #6
ParisLiakos commentedComment #7
ParisLiakos commentedlooks good and makes sense to me. i was just wondering if we could get a test here to make sure nothing breaks again in the future
Comment #8
sylus commentedAdding updated patch to use field_view_value.
Comment #9
sylus commentedSorry bad patch.
Comment #10
sylus commentedAttaching updated patch for latest media dev after the split into sub modules.
Comment #12
sylus commentedFunction isn't full form.
Comment #13
sylus commentedComment #15
sylus commentedThird time's the charm.
Comment #16
sylus commentedComment #17
sylus commentedUpdating the filter code as was only parsing the first MEDIA_WYSIWYG_TOKEN_REGEX found causing a duplicate on rendered node.
Comment #18
sylus commentedAttaching updated patch for latest dev. I will post a patch with tests within a week.
Comment #19
sylus commentedAttaching updated patch to latest dev of media (b2ba2da)
Comment #20
sylus commentedUpdating patch to fix: Cannot access empty property in field.attach.inc
Comment #22
letrotteur commentedI found it usefull to pass the langcode to the media_wysiwyg_token_to_markup alter
It solved a issue with translation of field inside a fielded entity inserted into the wysiwyg.
drupal_alter('media_wysiwyg_token_to_markup', $element, $tag_info, $settings, $langcode);
Comment #23
letrotteur commentedMade a patch with the addon...
Comment #24
sylus commentedThanks for the drupal_alter addon definitely makes sense to pass the langcode there as well.
Attaching new patch that applies to latest dev and which also works for 2.0-beta1.
Comment #25
sylus commentedComment #27
letrotteur commentedWorks great for me with 2.0-beta1.
Setting this To RTBC
Comment #29
joseph.olstadfixed in 7.x-2.x dev branch
Comment #30
sylus commentedThanks a bunch!
Comment #31
joseph.olstadThere's a regression with this patch that was reported by @shelane who is not using i18n , in her environment the langcode is undefined.
I've attempted to resolve the regression with a new patch in the followup issue. My strategy was to check for NULL langcode , I haven't tested the patch and I'm not yet sure if it'll pass simpletest as it's currently queued.
Please followup in the new issue.
#2822662: Media items added or edited no longer displaying addition fields
Your assistance is appreciated, this patch was tagged as a beta3 release so it'd be nice to fix this asap and push out a new release with the fix to this regression.