By hmdnawaz on
I have created a custom module and created a yml file to create a menu
system.menu.custom_menu.yml
id: custom_menu
label: 'Custom menu'
description: 'Custom menu.'
langcode: en
locked: true
dependencies:
- mymodWhen I installed my module it creates the the custom menu. But then When I uninstall the module and try to install it again I get the following exception
exception 'Drupal\Core\Config\PreExistingConfigException' with message 'Configuration objects (system.menu.custom_menu) provided by mymod already exist in active configuration' in
/var/www/drupal8/core/lib/Drupal/Core/Config/PreExistingConfigException.php:70What I am doing wrong? Is there any way to remove my configuration (system.menu.custom_menu) from the configurations when I uninstall my module?
Comments
i guess in d7 there is a
i guess in d7 there is a module hook
But no idea about d8....sorry.
https://www.drupal.org/project/image_captcha_indicator
https://www.drupal.org/project/ext_js
All configuration files are
All configuration files are stored in the Drupal 8 database "config" table. You can delete your "left over" configuration file there by looking it up in the table and manually deleting it which will allow you reinstall your module. If your module is not uninstalling correctly you can also uninstall it with Drush. When you choose the Uninstall tab from the Extend menu you should get a prompt advising you that uninstalling the module will delete the "config" files for the module. However, various things can happen during module development which prevent a clean uninstall.
Implement a hook_uninstall()
Implement a
hook_uninstall()in your modules install fileto delete a leftover schema you can use following command.
drupal_uninstall_schema('link_click_count');to leftover views you can delete with the help of view machine name.
OR
\Drupal::configFactory()->getEditable('views.view.link_click_count')->delete();hook_uninstall()
Thanks @ heykarthikwithu! that works fine for me.
Or You can use the Following code as well
---
Kind regards,
Thank you,
Rakesh James
Enforce a dependency on your module in the configuration
See How to remove mymodule configurations on uninstall for a best-practice solution.
Basically, you can enforce the dependency on your module in your configuration files. So when the module is uninstalled, it's associated configuration will be uninstalled as well.
You must set your custom
You must set your custom module as a dependency in your YML file by setting "enforced" under dependencies.
For example:
[deleted]
[deleted]
Using this after uninstalling
Using this after uninstalling the module I was not able to enable it because it is now dependent on itself. You should be fine without this unless you have submodules in which case defining dependencies may be useful. For some cases you may have to use hook_uninstall in the yourmodule.install file.
still working, thanks!
still working, thanks!
see also: https://drupal
see also: https://drupal.stackexchange.com/questions/164612/how-do-i-remove-a-conf...
https://drupal.stackexchange.com/questions/214132/is-there-a-way-with-dr...
None here seems like a viable
None here seems like a viable option for an instance with multiple config files. For example, my migration in development that has 10+ migrate_plus config files. I'm kind of in horror over what struggle it is developing this migration incrementally. i.e. having to reimport configs every time I make a change to a migrate file... and the need to delete them all somehow when things go awry. Not a good time.
How do you uninstall a plugin
How do you uninstall a plugin?
http://SocialNicheGuru.com
Delivering inSITE(TM), we empower you to deliver the right product and the right message to the right NICHE at the right time across all product, marketing, and sales channels.
hook_uninstall in drupal 8
Could you use hook_uninstall().
/**
* Implements hook_uninstall().
*/
function hook_uninstall() {
\Drupal::configFactory()->getEditable('system.site')->clear('remove_var_name')->save();
}
Thanks
Get the right dependency in .yml file
Get the right dependency in .yml file like in node.type.content_type_name.yml or field.storage.node___.yml files
dependencies:
enforced:
module:
- foobaryourmodulename