I'm creating a custom module based off of Bootstrap Paragraphs, with a bunch of configuration files for custom paragraph types.
The configuration includes a bunch of
field.storage. files, which AFAICT result in tables being created in the underlying MySQL data store for the respective fields.
The module is under active development, and I often need to reinstall it to pick up new changes.
Whenever I uninstall it and install it again, I get the error
Uncaught PHP Exception Drupal\Core\Entity\EntityStorageException: "'field_config' entity with ID 'paragraph.custom_component.custom_component_field' already exists." at /var/www/html/core/lib/Drupal/Core/Entity/EntityStorageBase.php line 425, referer: http://localhost:2345/admin/modules.
My best interpretation of this error is that the MySQL store already contains this table, so it can't be created.
Sure enough, when I access MySQL, the tables are there, even after module uninstallation.
Elsewhere, I've seen people say that in Drupal 8 uninstalling a module should cause all traces of the module to be removed, but that doesn't seem to be the case for me.
How can I set up my component so that it will delete the fields from the store when I uninstall it? Is there a better approach I should consider?
What I've tried
hook_uninstall()in the module file and adding the following code
\Drupal::configFactory() ->getEditable('field.storage.custom_component.custom_component_field') ->delete();
Renaming the config/install directory to config/optional
- Purging configuration using the "Purge Configuration" tab available from the Easy Install module