Needs review
Project:
Default Content
Version:
2.0.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
8 Oct 2020 at 18:56 UTC
Updated:
10 Jun 2025 at 13:13 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
heddnComment #3
heddnComment #4
Phil Wolstenholme commentedThis looks really useful, thanks for posting it @heddn.
I'm trying to make it so my default content node that represents the homepage is always node 1 as we set the value of
page.frontinsystem.site.ymlto be '/node/1'.What doesasortsort by? I tried renaming my homepage YML file to have a UUID that started with00000000to bring it to the top of the list but that didn't seem to work.----
Edit: Hmm, when I runprint_r(ContentFileStorage::scan('modules/custom/rocket_example_content/content/node'));my node YML file00000000-12f0-4087-a490-644a3dfd6894.ymlis at the top of the list, but it's not being created as NID 1, so maybe I've misunderstood what this patch will do. I'll try to do a bit more digging into how the module works out what order to create things in.Edit edit: Ah, they're sorted by dependencies and then created. Looks like I'll give up on my nice idea of NID 1 always being the homepage and use a hook to set my frontpage config value by loading the homepage node by its UUID then getting its ID.
Here's what I ended up going with:
Comment #5
berdiryou should avoid relying on ids, we by design build a dependency tree and that can change completely as if you add more content.
I guess the file sort might make it more predictable but it can still vary, also between different PHP versions for example as PHP likes to change its sort algorithms.
And yes, for places that need the ID like frontpage setting, you want to set it in an install hook or alternatively on the import event that we trigger. check if UUID x is being installed and then set that as as frontpage. I think that's a very common scenario, so I'm also open to supporting something like that specifically (also for 403/404 pages).
Comment #6
shelaneIn version 1.x, the entity ID was exported with the data. So for taxonomy terms, there was a tid with a value and then that value would be the tid when the content was imported. For taxonomy terms in a multisite, this is a must. They must all be the same so that when we do content sharing, the defined terms will all use the same IDs. I'm not sure why this is not an option in version 2.x.
Comment #7
Phil Wolstenholme commented@shelane exporting entity IDs in version 1 caused issues including things like #2969631: NID / VID / TID conflicts in branches, so the option was removed from version 2.
I wonder if https://www.drupal.org/project/entity_share might be more useful for your use case? Default content is primarily designed for providing default/example content for a single site, whereas Entity share is designed for content sharing between sites, I believe.
Comment #8
shelaneWe set up default taxonomy terms and menu items as each new multisite is installed so that they’re all consistent. It’s a one and done deal. We are currently adding about 2 sites per month.
Comment #9
jonketo commentedI have noticed that in some instances of imports when pages link to and reference each other they do not get set. Is this expected because the import can save pages in different orders?
Comment #10
karlsheaIn many cases this is impossible. I'm trying to use this module to add default block content and menu items that are required for config import before a D7 migration. When the migration runs it will only map block content by ID, since that was the only identifier in D7.
Hilariously with this patch applied the content is all created in the wrong order due to the
array_reverseinImporter::sortTree.Comment #11
omarlopesinoThis patch solves the problem for me, the content is always created in the same order. However, I agree with the sorting method's limitations as commented in #5. Until there is an agreement on a solid solution the patch proposed at #2 is completely recommended.
Comment #12
delacosta456 commentedhi
i was also having Nid constantly changing on import and would like to know if this issue and https://www.drupal.org/project/default_content/issues/3277477 are related
Comment #13
daniel.bosenAnother positive effect of this patch is, that lists that are ordered by creation or change date are predictable. This is not as easily fixable as forntpage and 40x settings.