Better support custom blocks in Layout Builder

Created on 27 March 2023, over 1 year ago
Updated 30 March 2023, over 1 year ago

As a site editor, I need to be able to export content (including media) created in Layout Builder from one environment and import on another.

While this module currently exports nodes created with Layout Builder with their layouts and custom blocks intact, any media they contain are not included and a "The referenced media source is missing and needs to be re-embedded." message displays in their place.

Is there a way to use the work in https://www.drupal.org/project/single_content_sync/issues/3346367 ✨ 3346367-embed-media Fixed so that media within the bodies of custom blocks is also included in the export?

✨ Feature request
Status

Fixed

Version

1.3

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States cameron prince

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

Comments & Activities

  • Issue created by @cameron prince
  • Status changed to Postponed: needs info over 1 year ago
  • πŸ‡ΊπŸ‡¦Ukraine nginex

    Hi @cameron prince,

    I did quick test and could not spot the bug. Here are the steps I used:

    1. Create a node that supports a layout builder
    2. Add a custom block with embed media into WYSIWYG to layout builder.
    3. Go to export page and click on "Download as a zip with all assets"
    4. Uncompress generated zip file and verify all the assets exist.
    5. Delete the content you exported.
    6. Go to impoty page and upload the generated zip
    7. Verify newly imported content, everything is in place.

    Could you please provide mode details? Maybe I am missing something...

  • πŸ‡ΊπŸ‡¦Ukraine nginex

    Attaching screenshots with the layout export and uncompressed generated zip.

  • πŸ‡ΊπŸ‡ΈUnited States cameron prince

    When you deleted the content you exported, did you also delete the media entity and its corresponding file entity?

    I took the exact same steps, but instead of deleting the content manually, I reimported the DB from a backup I'd made prior to creating the content.

    Thanks for the help!

  • πŸ‡ΊπŸ‡¦Ukraine nginex

    I did this test again, but now I uploaded new custom images, exported the content, removed that database, clean up my local files, installed the site from scratch and reimported zip with previously generated images. Everything worked as designed with the fresh database.

    I'm wondering, have your assets been successfully exported into the zip?

  • πŸ‡ΊπŸ‡ΈUnited States cameron prince

    Here's the export I downloaded after creating the test node.

    I will re-test and document to confirm. Maybe I missed something.

  • πŸ‡ΊπŸ‡¦Ukraine nginex

    Yeah, assets folder is missing, and also blocks is empty udner layout_builder__layout_2_col. So it does not export blocks properly which means there is nothing to import.

  • πŸ‡ΊπŸ‡ΈUnited States cameron prince

    Hmmm. It does seem to export the blocks themselves. They appear after importing on the fresh DB restore. It's just that the media in their bodies isn't also included in the export.

    Do you think it's something with our particular structure? I'm not sure how to troubleshoot.

  • πŸ‡ΊπŸ‡ΈUnited States cameron prince

    One thing to note, we're using the Layout Builder Overrides module ( https://www.drupal.org/project/layout_builder_overrides β†’ ) which allows the default layout to be overridden per view mode, rather than only the default view mode. I wonder if this is the culprit.

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

    I think I have found the issue by inspecting you layout value.

    Your block inside section component has empty value for block_revision_id, so the block can't be exported as you can see in the code https://git.drupalcode.org/project/single_content_sync/-/blob/1.3.x/src/...

    But there is block_serialized, so now it's possible to provide a patch and fix the issue with this information.

  • πŸ‡ΊπŸ‡ΈUnited States cameron prince

    Here's another test on a fresh setup. This time, I put an image in the body field and assigned it to the middle column. The two side columns have custom blocks, one with an image and the other with just text.

    The image on the body is exported properly, but as you mentioned, the blocks element is empty and I don't see the image file in the export for the image in the block.

  • πŸ‡ΊπŸ‡ΈUnited States cameron prince

    Ah, you are correct... We don't have revisions turned on for custom blocks. I'll switch it on and give it a try.

  • πŸ‡ΊπŸ‡ΈUnited States cameron prince

    I've enabled revisions on the basic block custom block type and tried again. It didn't seem to change anything. Here's the export.

  • @nginex opened merge request.
  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡¦Ukraine nginex

    Added a patch to properly export blocks that are serialized. Could you please test how exporting and importing working with the patch from MR?

  • Status changed to RTBC over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States cameron prince

    It works splendidly well! Thank you so much!

    This really rocks!

    • nginex β†’ committed 8aa47d2b on 1.3.x
      Issue #3350683 by nginex: Better support custom blocks in Layout Builder
      
  • Status changed to Fixed over 1 year ago
  • πŸ‡ΊπŸ‡¦Ukraine nginex

    Thanks for checking, I'm glad we found the issue and improved the module.

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

    This is now available in the new module release.

Production build 0.71.5 2024