3346367-embed-media

Created on 6 March 2023, almost 2 years ago
Updated 23 March 2023, over 1 year ago

Problem/Motivation

When exporting a body field with CKEditor enabled with the Media Embed plugin, the module doesn't export the embedded media asset.
When importing the exported content, you get all the CKEditor content, even the <media-embed></media-embed> tags, but because the CKEditor Media Embed plugin can't find the data-uuid attribute on its media gallery, it is rendered broken.

Steps to reproduce

Enable the Media Embed CKEditor plugin on a text format.
Create an article and insert a new image using the Media Embed CKEditor plugin.
Save the node.
Export the node.
Import the node into a different environment where the inserted image doesn't exists yet.

Proposed resolution

Export embedded medias on long-text field type, then create the same media uuid when importing to make it available for the Media Embed CKEditor plugin.

✨ Feature request
Status

Fixed

Version

1.3

Component

Code

Created by

πŸ‡¦πŸ‡·Argentina drupal-son

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

Comments & Activities

Not all content is available!

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

  • πŸ‡¦πŸ‡·Argentina drupal-son

    Hi @nginx and folks, any update on this?
    Is this a bug or a feature request to support entity (media in this case) embeds on WYSIWYG when exporting?

    Thanks for this great module.

  • πŸ‡ΊπŸ‡¦Ukraine nginex

    Hi @drupal-son,

    Thanks for the feedback, this issue looks like a feature request, I was not thinking of having a possibility to support embed entities in WYSIWYG when created the module, in any case this is a great idea and I already have a few ideas how to provide support for this.

    I think I can develop this feature later this week and provide a new release e.g. 1.4

  • πŸ‡¦πŸ‡·Argentina drupal-son

    That sounds great!

    SCS module is really really useful, I'm using it to replacing a full database clone from environments (which I hate), but as soon as my user finds a use case when it doesn't export a specific field, he push back to database cloning method again.

    I envision this module could be part of Core not too late.
    The Entity Embed into WYSIWYG solution is widely used in multiple websites, so the module must support it In order to be part of it.

    I would like to contribute somehow, I reviewed the documentation page https://www.drupal.org/docs/contributed-modules/single-content-sync/expo... β†’ for trying to understand the underlying data structure, but because the exports run on a batch, it is not easy to debug.
    Can you point me with better real examples on how to extend the module to support a custom fields or not-yet-supported contributed fields?

    The fix for my other feature request https://www.drupal.org/project/single_content_sync/issues/3332663 πŸ› Avoid importing entity into another website Fixed worked amazingly, even more features that I imagined. Thank you for that.

  • πŸ‡ΊπŸ‡¦Ukraine nginex

    What a nice feedback!

    If you wish to contribute a solution for this issue you can looks how layout_section field type is exported and do similar for text_long

    https://git.drupalcode.org/project/single_content_sync/-/blob/1.3.x/src/...

    1. Collect media entities from WYSIWYG text value and export them sepratly into a dedicated property as it's done for blocks in the example.

    Btw you can do the same with contributation by using hook_content_export_field_value().

    2. See implementation of MediaEmbed::process() to see how to getch media entities from the text.

    3. Import entities for the text_long similar to layout_section, but much simpler https://git.drupalcode.org/project/single_content_sync/-/blob/1.3.x/src/...

  • @nginex opened merge request.
  • Status changed to Needs review almost 2 years ago
  • πŸ‡ΊπŸ‡¦Ukraine nginex

    Hey @drupal-son, I added the fix to the issue, you can test it by applying a patch from MR, if it's working for you change status to RTBC.

    It was easier that I thought ;)

  • πŸ‡¦πŸ‡·Argentina drupal-son

    OMG, you are faster than me :)
    Let me test the patch and I'll let you know in a bit.

    Thanks.

  • πŸ‡¦πŸ‡·Argentina drupal-son

    @nginex Sorry for the delay, not so easy to test as I need 2 environments with the patch applied.

    The YML file looks good, I compared it before and after the patch, and now it seems to have the embedded entity with all its attributes.
    However, the image itself on the assets folder wasn't generated.
    When imported, the media entity was created but with a broken default image.

    Does it make sense?

  • πŸ‡ΊπŸ‡¦Ukraine nginex

    I tested on Umami Food Magazine profile Drupal 9.5 and I used Download as a zip with all assets and it worked without issues. Did you test with other fields that are referencing to media if they are exporting with generated assets?

  • πŸ‡¦πŸ‡·Argentina drupal-son

    The content type has other referenced media entities fields, for those cases, the images were exported without issues.

    Another thing to mention, my long_text contains more than 1 media embed (3 of them to be more exact), also more than 1 long_text field too with multiple
    media embeds.
    The yml contains the 3 uuid but the images are not into the assets folder.

    I’m not at the desk right now, I need to check the content type structure, but it might be possible that this is a multi value paragraph that contains some fields and the long text with media embeds into it.

  • πŸ‡¦πŸ‡·Argentina drupal-son

    @nginex I can confirm that my content type has some paragraph multivalue fields, where the paragraph contains the long text WYSIWYG field, where multiple media images are embedded. These images are not exported into the zip package.

    Just for clarifying, at the same time, the content type has media fields. These images are exported fine into the zip package.

  • πŸ‡ΊπŸ‡¦Ukraine nginex

    @drupal-son thanks for reporting, I have enough information to reproduce the issue

  • πŸ‡¦πŸ‡·Argentina drupal-son

    Were you able to reproduce the issue?

    Do you think it is useful to share my yml file so you can see the generated structure?

  • πŸ‡ΊπŸ‡¦Ukraine nginex

    @drupal-son, it would be nice if you could share your yml file.

    I'm going to test it today with similar structure

  • πŸ‡¦πŸ‡·Argentina drupal-son

    @nginex this might sound weird but I was able to make the patch work, not sure why it didn't work the last time.
    I think this is RTBM.

    BTW, I was also able to export a custom field using the export/import hooks. It worked like a charm.

  • Status changed to RTBC over 1 year ago
  • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

    Tested the solution on the two existing project + on the empty project.

    Steps:
    * installed module single_content_sync
    * installed this patch
    * prepared the test content
    ** added media image to the formatted text field
    ** added media file to the formatted text field
    ** added paragraph with formatted text field
    ** added media image to the formatted text field of the paragraph
    ** added media file to the formatted text field of the paragraph
    * exported the entity with all assets
    * removed test content
    * removed related media entities
    * removed related files
    * imported data on the same site and checked the result - OK
    * imported data on the other site but with the same structure - OK

    The fix worked as expected.

    • 3379f4f0 committed on 1.3.x
      Issue #3346367: Add support of embed entities from CKEditor
      
  • Status changed to Fixed over 1 year ago
  • πŸ‡ΊπŸ‡¦Ukraine nginex

    Thank you all for testing.

  • Status changed to Fixed over 1 year ago
  • πŸ‡ΊπŸ‡¦Ukraine nginex

    The fix is available in the new release.

Production build 0.71.5 2024