I created a custom module which essentially is a replica of the Article
CT .yml files which come with the D8 standard install-profile.
When I installed the custom module, it successfully created everything i expected it too. I then disabled it, then re-enabled and the module will not re-install giving the following error:
Drupal\Core\Entity\EntityStorageException: 'field_storage_config' entity with ID 'node.custom_field' already exists.
I originally solved this issue by declaring the module as a Enforced dependency on the node.type.yml
langcode: en
status: true
dependencies:
module:
- menu_ui
enforced:
module:
- custom_module
This worked for the body field and allowed me to enable/disable the module without getting the duplicate ID error. but as soon as i added the image field the ID is a duplicate and I cannot re-enable the module. The id is unique, and module will enable if i change the ID prior to enabling, but thats unacceptable.
EDIT: appears after removing the image field from the CT, the body field now is now being affected by the same error. So enforcing the module doesnt work.
I would assume this is because it is inside of the config/install
folder, but there are no examples on custom modules that install content types when installed. at least I cannot find any at the moment.
My question would be: What is the proper way to add content types when enabling a custom module?
how to avoid the duplicate ID error when installing content types when disabling/enabling the custom module?