Allow defining custom import order

Created on 23 July 2025, about 1 month ago

Problem/Motivation

Currently, the Default Content module in Drupal allows importing content entities from exported YAML files, but it does not provide an option to define a specific import order for those entities.

This limitation can cause issues in scenarios where certain content must exist before others.

This feature would be particularly useful in automated testing or development setups where predictable and reproducible content creation is required.

Steps to reproduce

  • Create a custom module that uses default_content to provide default content (nodes, taxonomy terms, etc.).
  • Export multiple content entities, including dependencies (e.g., nodes referencing taxonomy terms).
  • Attempt to import them using drush default-content:import or the module installation process.
  • Observe that there is no way to define the import order; the system processes content in an unspecified sequence.

Proposed resolution

Introduce a custom sorting mechanism in the module’s .info.yml file that allows developers to define the order of content import using entity UUIDs grouped by entity type. For example:

custom_sort:
  node:
    - b7a9391c-c6f6-49a8-acb3-53e338138073
    - ee156ff4-629f-440d-b384-2d651a0f60db
    - 4fcbcb4c-55b9-44d9-962e-06085deec664
  taxonomy_term:
    - 03d8d361-8c79-4e70-b061-60dbbffac975
    - 810da89e-59b6-4bce-9fe3-7301ae7572a2
✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

🇪🇸Spain lpeidro Madrid

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

Merge Requests

Comments & Activities

  • Issue created by @lpeidro
  • Pipeline finished with Success
    about 1 month ago
    Total: 175s
    #554895
  • 🇪🇸Spain lpeidro Madrid

    It is necessary to add unit tests.

  • Pipeline finished with Success
    about 1 month ago
    Total: 147s
    #554908
  • First commit to issue fork.
  • Pipeline finished with Success
    about 1 month ago
    #559555
  • 🇪🇸Spain frouco

    The order of the entity types in the 'custom_sort' is now taken into account when sorting the import order.

    When the default content has several dependencies, the order of the entity types provided by entityTypeManager->getDefinitions() is more relevant than the order of the .yml files due to the dependency tree.

    Use case: The order provided by entityTypeManager->getDefinitions() is alphabetical, so if the default content has comments, they will determine the import order of the nodes, users, etc.

Production build 0.71.5 2024