Content export feature (including layout builder content)

Created on 3 March 2020, over 4 years ago
Updated 8 June 2024, 20 days ago

Summary

I have implemented a system in order to export the existing content in the Drupal database in a format that Migrate Default Content understands.

Key features:

  • Content exporting. You can create the content via web and then run a command to have the content exported to files.
  • Layout Builder integration. The entities using Layout Builder are successfully exported and imported again.

Motivation

I love Migrate Default Content. It's a great module to provide a site full of content to the client when delivering the product. However, it can be a little bit confusing to work with it. Specially when working with related content. In addition, the content using layout builder is almost impossible to integrate.

Proposed solution

I have implemented two commands. One that exports the content to several files and another one for aggregating all of those files and creating the YML files that are understandable by Migrate Default Content.

So, a normal workflow would be:

1- I create content in the website via UI
2- I run `drush mdce` (migrate default content export) that will create a single YML file for each content entity
3- I run `drush mdcby` (migrate default content build yamls) that will read all the generated files in the step above and create the single YML file (per entity, bundle and language) that Migrate Default Content understands

Then use `drush migrate-import --tag=migrate_default_content` as normal.

Considerations

  • The only entity that keeps the identifier is the taxonomy term (normally used in views to filter)
  • When executing `drush mdce`, the existing files are never deleted so if you delete an entity by UI, you have to delete the matching file in order to avoid to create the entity again in the next migrate-import.

Any feedback will be welcome!

✨ Feature request
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain unstatu

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 spotzero

    Here's the rerolled patch which combines the fixes from 9 and 10.

    I really like this functionality, but I agree it's different enough where there is a benefit of putting it in it's own module, if only to seperate the logic. I've started looking through the patch to either clean it up or spin into it's own module.

  • πŸ‡¨πŸ‡¦Canada NickDJM

    Just to give an update to this issue:

    The current patch in #11 does not work. I have a fix that I will be posting shortly in a MR with the updated drush command syntax.

    As for this issue as a whole, we will be splitting this out into a sub module. This functionality is super useful and we don't want it to live as a "forever patch", however the code written in the patch needs a lot of work. At a bare minimum it does not meet the Drupal coding standards, nor is it documented sufficiently.

    Once we have a MR open for this, it will be kept alive while we work on a new branch with cleaned up code. The first goal will be to allow exporting of what MDC can already handle (basically removing the layout builder functionality for now), then we will be reducing the number of drush commands to a single command that allows users to pass options to it for what entities/bundles they want. Once this is functional we will implement the Layout Builder functionality.

    I'd also like to give a big thanks to everyone who has contributed to this issue so far. We use this patch constantly. It's time to see it implemented officially.

  • Merge request !6Draft: feat: add content export feature β†’ (Closed) created by NickDJM
  • πŸ‡¨πŸ‡¦Canada NickDJM

    Ok MR has been created and everything is working about in D10.2.2.

    The next steps will be to refactor this into something we can split out properly into a submodule: migrate_default_content_export

    First will be to get basic entities working (nodes, blocks, terms, etc.) with no layout builder functionality. Once this is done, we'll look at the layout builder stuff.

  • Assigned to NickDJM
  • πŸ‡¨πŸ‡¦Canada NickDJM

    Updating the issue to point to the version of MDC that the MR applies to.

  • πŸ‡¨πŸ‡¦Canada NickDJM

    An update on this: me rerolling the patch and fixing the drush commands didn't work. There's some other weirdness going on with layout builder I think.

    That being said, I have a branch off the main module where I am implementing this as it's own module.

    On my testing site I have it working. It exports content in all languages and puts them into yaml files as expected. I still need to test it out on other sites (and get layout builder support in), but it looks promising.

    I have added filters so you can include/exclude entities, bundles, and ids.

  • Status changed to Fixed 5 months ago
  • πŸ‡¨πŸ‡¦Canada NickDJM

    This feature has been rolled into 3.0.0-alpha0. Please use that version of the module for the ability to export content.

    We will keep track of any other issues related to this (since I'm sure there will be some) in their own issues.

    As for this issue, I consider it fixed.

  • Automatically closed - issue fixed for 2 weeks with no activity.

  • πŸ‡ΊπŸ‡ΈUnited States lhridley

    What happened to the Layout Builder data? Looks like it was removed at some point. Where is the open issue in the issue queue where this is being included. If it is in another contrib module or a submodule, where can that project be found?

Production build 0.69.0 2024