I feel like there is a step missing in the documentation. After I follow these steps:

Enable default content first. Any module that requires default content can put hal+json versions of the entities (created with the drush commands) inside content/{entity_type} folders.

What actually imports the json? Enabling my custom module? This is unclear to me and possibly others. My use case follows this model:

modules/default_content_test/content
modules/default_content_test/content/node
modules/default_content_test/content/node/imported.json

Also, what happens if you have multiple nodes that you want to import? I can update the documentation with the results of this issue.

THanks

Comments

robpowell created an issue. See original summary.

larowlan’s picture

Category: Bug report » Support request

It runs after the module is installed, using hook_modules_installed

robpowell’s picture

@larowlan thanks for the quick response!

Say if I want to test this locally, I used the drush command to create three json files (for my three nodes) under custom_module/content/node. Do I have to now delete those nodes or will the module know not to add an entity that already exists?

Currently, when I enable the module, I am getting sql integrity constraint violations :

Next exception 'Drupal\Core\Entity\EntityStorageException' with message
'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '3' for
key 'PRIMARY': INSERT INTO {node} (nid, vid, type, uuid, langcode) VALUES
(:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2,
:db_insert_placeholder_3, :db_insert_placeholder_4); Array
(
    [:db_insert_placeholder_0] => 3
    [:db_insert_placeholder_1] => 3
    [:db_insert_placeholder_2] => page
    [:db_insert_placeholder_3] => 1f2a26c0-08fa-49b9-b985-3509c20f49d4
    [:db_insert_placeholder_4] => en
)
' in
robpowell’s picture

So I blew away (deleted) the content that I had exported through the UI. Once I re-enabled my module the content was automatically created. Is there a bug already tracking that it currently breaks if the entity currently exists?

larowlan’s picture

robpowell’s picture

great I added a sentence to the documentation that I think clears it a bit, well for me anyways.

Enable default content first. Any module that requires default content can put hal+json versions of the entities (created with the drush commands) inside content/{entity_type} folders. Once your custom module is enabled, the entities you exported will be imported to the new environment.

andypost’s picture

You also need to clean-up uid0 & uid1 in export if they appear here

berdir’s picture

Status: Active » Closed (outdated)

I've recently created the 2.0.x branch, see the project page on all the improvements in the 2.0.x branch. Testing that and providing feedback would be very welcome. The 1.x branch isn't actively maintained and won't receive new features anymore, so I'm closing this and other issues as won't fix.

Existing entities is covered in #2698425: Do not re-import existing entities and the uid0/1 is fixed in 2.0.x