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 like config_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

swentel’s picture

larowlan’s picture

andypost’s picture

slucero’s picture

The 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.

SocialNicheGuru’s picture

alexpott’s picture

The 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.

alexpott’s picture

Contrib 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.

andypost’s picture

Demo 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

alexpott’s picture

@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.

nedjo’s picture

As well as Default Content, some other similar modules in contrib (at varying levels of stability/completeness) are:

huzooka’s picture

I also wrote a PoC module which exports the specified content into migrations: Entity Migrate Export

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

nerdstein’s picture

Drupal 8 has support for default config entities, but not for default content entities.

It could be useful to identify code that is potentially reusable

nerdstein’s picture

Pasqualle’s picture

I would prefer a migrate based approach for default content.

nedjo’s picture

There 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:

  • Config entity handling in ConfigInstaller and ConfigImporter.
  • The migrate API.
  • Serialization + REST.

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:

Marios Anagnostopoulos’s picture

@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 :).

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

bsnodgrass’s picture

Issue summary: View changes

This 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.

andypost’s picture

Version: 9.5.x-dev » 11.x-dev
Related issues: +#2849128: Add handling of ConfigEvent::IMPORT_MISSING_CONTENT

It still smells like experimental default content module in core so it's related in its queue #2849128: Add handling of ConfigEvent::IMPORT_MISSING_CONTENT