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
Issue fork default_content-3537584
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
lpeidro commentedIt is necessary to add unit tests.
Comment #5
frouco commentedThe 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.