Drupal has support for default config entities, but not for default content entities. As menu links are content entities, #2047633: Move definition of menu links to hook_menu_link_defaults(), decouple key name from path, and make 'parent' explicit tries to come up with a custom approach to define default links. As this is custom, we cannot use this for anything else. Contributes projects such as Devel and Commerce Kickstart already provide default content in D7, so it makes sense to provide a generic way to do this in Drupal.
Our roadmap doc identifies this issue as a ToDo for Phase 1.
Proposal
- Store default content entities as YAML files in modules' /content directories.
- Content entity type annotations get a
content_prefix
property of which the value maps to the YAML files, just likeconfig_prefix
does for config entities. - During installation the system scans for default content, turns them into entities and calls the save() method on them.
Next steps
- Review and confirm the proposal
- Cleanup docs
Comments
Comment #1
swentel CreditAttribution: swentel commentedMore discussions over at #79582: Add example content to the experimental out-of-the-box demo install profile
Comment #2
larowlanNote https://github.com/larowlan/default_content
Comment #4
andypostComment #9
sluceroThe YAML Content module supports some of this approach as well.
https://www.drupal.org/project/yaml_content
The automatic installation of content with a module isn't implemented, but this could easily be added using available services through the install hook.
Comment #15
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedhttp://drupal.org/project/default_content
Comment #16
alexpottThe ability to create default content as part of installing things in Drupal has become an aim for #3274999: Distributions and Recipes initiative overview and roadmap therefore I think we should make this issue a part of it.
Comment #17
alexpottContrib has a pretty mature solution - the default content module but @larowlan wrote https://www.previousnext.com.au/blog/we-could-add-default-content-drupal... a while back about the issues.
I think we need to update the issue summary with steps we need to take to bring something like it into core. I feel the supporting the 2.x yaml file format would be a big boon as it would allow people to move from contrib to core with little change.
Comment #18
andypostDemo umami using migrations for initial content
Looks it's shortest route to reuse it
Also we using https://www.drupal.org/project/migrate_generator on custom projects
Comment #19
alexpott@andypost demo umami is not using migrate as far as I know. See \Drupal\demo_umami_content\InstallHelper - it's custom all the way down.
Comment #20
nedjoAs well as Default Content, some other similar modules in contrib (at varying levels of stability/completeness) are:
Comment #21
huzookaI also wrote a PoC module which exports the specified content into migrations: Entity Migrate Export
Comment #23
nerdsteinIt could be useful to identify code that is potentially reusable
Comment #24
nerdsteinQuick search on some prior art for default config
tests for "default config"
default config storage: DEFAULT_COLLECTION constant in the storage interface, used by the tests, seems to be relevant
Comment #25
PasqualleI would prefer a migrate based approach for default content.
Comment #26
nedjoThere seems to be a general consensus in this issue that we ought to base a solution on a relevant core API. The problem is, which one? We have at least three different solutions in core for the general problem of defining and installing/creating/importing an entity with its associated properties:
ConfigInstaller
andConfigImporter
.Choosing between them is not straightforward. What seems key is to first make sure we're clear on the spec.
There are at least three related use cases: importing, updating, and staging content. If all three are valid, we should build an API that, even if it doesn't immediately support all three, could do so in future.
Related:
Comment #27
Marios Anagnostopoulos CreditAttribution: Marios Anagnostopoulos commented@alexpott
I think that most of the issues that are mentioned in the Blog post you attached, have already been tackled one way or another in the default_content module.
@nedjo
I would not count REST and Migration as valid ways to have 'default' content.
In my understanding.. 'default' means demo content or content that you want to have tracked during development (Some basic pages / terms etc). I don't think that the default content aspect of drupal should handle massive numbers of imported entities. That is handled by migration :).
Comment #29
bsnodgrass CreditAttribution: bsnodgrass at net2Community, Inc. commentedThis is a Roadmap ToDo Issue for Phase 1 of the Distributions and Recipes Initiative. Besides updating the Issue Summary, are there some child issues that should be created for this issue?
I am taking a first pass at some minor updates to the summary.
Reviewing a related docs https://git.drupalcode.org/project/distributions_recipes/-/blob/1.0.x/do..., I am creating an issue to remove "Deploying the content created by a Drupal recipe is out-of-scope." which conflicts with the project Roadmap.
Comment #30
Wim LeersRelated:
Comment #31
andypostIt still smells like experimental default content module in core so it's related in its queue #2849128: Add handling of ConfigEvent::IMPORT_MISSING_CONTENT
Comment #32
andypostPrimary blocker is found and fixed #3414993: Add ConfigImporter to \Drupal\Core\Config\Importer\MissingContentEvent