Add content_translation support

Created on 19 October 2022, about 2 years ago
Updated 21 June 2024, 5 months ago

Problem/Motivation

On my project, I'm using a module called Content Translation and just started to use the Media Library Edit because of an alttext translation demand.
When using the module content_translation, we can create translations for contents. Doing so with image fields, enable us to add an alttext for each language, for example.
It would be very helpfull that we could create (and maybe see more) a new translation in the modal added by this module so we don't need to search for the image on the Media Library to do so.

Content Translation online documentation: https://www.drupal.org/docs/7/multilingual/translating-content โ†’

Steps to reproduce

Enable module Content Translation. [content_translation_module]
Register some languages available.
Configure it and enable translation for media - image types and select the translatable fields.
It should appear a tab on each node where you can see tranlastions and add new ones. [translate_tab]

Proposed resolution

I'm trying to work on a resolution for that, so it would be very helpfull to hear other points of view and discuss problems and ideas.
I was trying two solutions:

  1. Enable to switch tabs on the modal too
  2. Edit the edit-form and add the translatable fields and options at it

Any ideas?

Remaining tasks

Add tests for:

  1. Make sure it does not cause fatal error when visiting field settings route. See steps on ๐Ÿ› Error: Call to undefined method Drupal\field_ui\Form\FieldConfigEditForm::getFormLangcode() in media_library_edit_field_widget_single_element_form_alter() (line 123 of modules/contrib/media_library_edit/media_library_edit.module) Closed: duplicate
  2. Make sure it does not hide CKEditor 5 buttons after editing translated media in dialog.

User interface changes

API changes

Data model changes

I'm new here in the community, so please, let me know if there is any information missing.

โœจ Feature request
Status

Needs work

Version

3.0

Component

Code

Created by

๐Ÿ‡ง๐Ÿ‡ทBrazil rstroh

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada vincent signoret

    Hello, thank you for the work.
    I wondering if we can have this patch for the 3.0.x ?

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands arantxio Dordrecht

    So I've worked on a patch for the latest 3.x dev version as of today. I think I've gotten everything that was in the issue fork. Patches are attached.

    When testing I noticed some layout issues while having GIN and Claro installed on our site. So I've also created a patch for when that happens. Example also attached, So if you have the same issue as use while having GIN as your admin theme, then try that patch or use it as a example if your issue is different from ours.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • First commit to issue fork.
  • @robpowell opened merge request.
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States robpowell Boston

    I updated media_library_edit-3316163 with latest 3.x changes, gin fixes in #14 and a typo in render array 'attached' vs '#attached'.

    To test I did the following:

    1. translated a node
    2. on the edit page for that node I went to the media field. For each media that didn't have a translation, there was a button to translate
    3. clicking the "translate" button shows a modal and allows for editing the translation.
    4. saving the node and inspecting the image shows the translated translation
    5. reviewing the entity at /admin/content/media confirms that there is a translation

    Note: On Gin theme the dropdown button active state looks a bit off:

  • Status changed to Needs work about 1 year ago
  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland sokru

    Accidentally created a new issue ๐Ÿ› Error: Call to undefined method Drupal\field_ui\Form\FieldConfigEditForm::getFormLangcode() in media_library_edit_field_widget_single_element_form_alter() (line 123 of modules/contrib/media_library_edit/media_library_edit.module) Closed: duplicate , when the cause was this issue. The patch on #14 needs something like:

    --- a/media_library_edit.module
    +++ b/media_library_edit.module
    @@ -17,6 +17,7 @@ use Drupal\Core\Field\WidgetInterface;
     use Drupal\Core\Form\FormStateInterface;
     use Drupal\Core\Routing\RouteMatchInterface;
     use Drupal\Core\Url;
    +use Drupal\field_ui\Form\FieldConfigEditForm;
     use Drupal\media\Entity\Media;
     use Drupal\media_library\MediaLibraryUiBuilder;
    
    @@ -116,6 +117,9 @@ function media_library_edit_field_widget_single_element_form_alter(array &$eleme
           $element['#attributes']['class'][] = 'js-media-library-edit-' . Html::cleanCssIdentifier($context['items']->getFieldDefinition()->getName()) . '-wrapper';
           /** @var \Drupal\Core\Entity\ContentEntityFormInterface $form_object */
           $form_object = $form_state->getFormObject();
    +      if ($form_object instanceof FieldConfigEditForm) {
    +        return;
    +      }
    
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada vincent signoret

    I couldn't install the patch on Drupal 10.1.2 on 3.0.2
    I don't know if it's related to #19

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands arantxio Dordrecht

    I've added the changes from โœจ Add option to select form display mode Fixed . Which adds the option to set the form_mode.
    Tested it on our local environment and seems to be working fine.
    This should make it work on the latest dev branch.

    we will still have to look at the problems in comment #18. with the allignment.

    and I also haven't looked into #19 yet.

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands arantxio Dordrecht

    Here is the patch, because the MR needs to be updated first. @robpowell could you update your MR to target the dev branch origin/3.0.x ? I don't seem to be enable to do so, I could create a new MR, but that wouldn't be the best option IMO.

  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland sokru

    Added the remaining tasks. We found out a new issue with the patch (22): the Body field WYSIWYG (CKEditor 5) buttons disappear after editing&saving the translated media item alt-text in dialog. I can reproduce the issue with 10.1.5 and 10.2.x, and removing the patch (#22) will fix the issue.

  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland sokru

    Have been trying to debug the CKEditor field converting into plain textarea after submitting the media field translation dialog.
    What I have tried so far:
    - Drupal with different core versions (9.5.x, 10.1.6, 10.2.)
    - Switch the WYSIWYG field to use CKEditor 4
    - Hardcoding the core/ckeditor5 dependency to module and #attached libraries.

    Once this is resolved I think it would greatly help to tackle the regression if we could add the tests. Wrote the manual steps how to reproduce the issue.

    composer require drupal/admin_toolbar drupal/media_library_edit:3.0.x-dev drush/drush
    vendor/bin/drush en content_translation media_library_edit media_library -y
    cd modules/contrib/media_library_edit
    curl -O https://www.drupal.org/files/issues/2023-09-11/3316163-22.patch
    patch -p1 < 3316163-22.patch
    # Add a new language
    http://localhost:8888/admin/config/regional/language/add
    # Allow translating node:article
    http://localhost:8888/admin/structure/types/manage/article
    # Allow translating media:image
    http://localhost:8888/admin/structure/media/manage/image
    # Create a new media reference field with media:image
    # Make sure "Users may translate this field" is checked
    http://localhost:8888/admin/structure/types/manage/article/fields/add-field
    # Make sure "Show edit button" is checked on Media field
    http://localhost:8888/admin/structure/types/manage/article/form-display
    # Add a new article and add media:image
    http://localhost:8888/node/add/article
    # Translate the article and edit the media field.
    # After submitting the media dialog, the CKEditor field changes to plain textfield.
    
  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland sokru

    For anyone looking a temporary solution with WYSIWYG editor disappearance, I've created a following core patch.

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland Lukas von Blarer

    Lukas von Blarer โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland Lukas von Blarer

    I decided to create a new branch and MR based on the existing MR. I didn't make any changes.

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands arantxio Dordrecht

    I've merged the changes from the latest commit on the Dev branch.

    I excluded the part for the FormattableMarkup as we display it different, also it creates a visually hidden span element, which makes it obviously visually hidden.

  • #14 for gin works for me ( media_library_edit 3.0.3 and D 10.2.5 )

    I hope it will be released soon, This is such an essential feature in my mind.

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands arantxio Dordrecht

    @daisyleroy If you would like to use the MR, you would have to use the dev branch for media_library_edit, as it is one change ahead of the release tag.

    I do have to say, we experienced some visual bugs with the MR like in #18. So some work on styling has to be done first imo.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain rcodina Barcelona

    @Arantxio I tried the MR17 but the patch fails to apply:

    I executed this command to get the 3.0.x version which is the target branch of MR17:

    composer require 'drupal/media_library_edit:dev-3.0.x'

    Then I added the patch like this:

    "drupal/media_library_edit": {
       "Add content_translation support": "https://git.drupalcode.org/project/media_library_edit/-/merge_requests/17.patch"
     }

    But composer gives an error:

    Could not apply patch! Skipping. The error was: Cannot apply patch https://git.drupalcode.org/project/media_library_edit/-/merge_requests/1...

  • ๐Ÿ‡ญ๐Ÿ‡บHungary nagy.balint

    MR17 was based on 3.0.2, and the merge with 3.0.x did not work out apparently.

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands arantxio Dordrecht

    I've update the MR to be based back on the 3.0.x branch, which should work no problem, as we have been using it for some time.
    The dev branch can be checked out as followed:
    "composer require 'drupal/media_library_edit:3.0.x-dev@dev'"

    Here is the current git tree:

    And how its set within our composer file:

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands arantxio Dordrecht

    I've also created a patch based on #14 but then for 3.0.3 and with the fix mentioned in #19, hope this helps

Production build 0.71.5 2024