- πΊπΈUnited States dww
Sweet, that looks pretty good on visual inspection. Needs manual testing, at least. Perhaps even an automated test, but I'm not sure I care that much. π
- Status changed to RTBC
about 1 year ago 12:40am 7 November 2023 - πΊπΈUnited States trackleft2 Tucson, AZ πΊπΈ
While this works, I think we should also add the following (recommended approach) to all config files that should be uninstalled when its owning module is uninstalled.
In all of these files:
modules/examples/config/install/core.entity_form_display.node.node_form_mode_example.contributor.yml modules/examples/config/install/core.entity_form_display.node.node_form_mode_example.default.yml modules/examples/config/install/core.entity_form_mode.node.contributor.yml modules/examples/config/install/core.entity_view_display.node.node_form_mode_example.default.yml modules/examples/config/install/core.entity_view_display.node.node_form_mode_example.teaser.yml modules/examples/config/install/field.field.node.node_form_mode_example.body.yml modules/examples/config/install/field.field.node.node_form_mode_example.field_picture.yml modules/examples/config/install/field.storage.node.field_picture.yml modules/examples/config/install/node.type.node_form_mode_example.yml modules/examples/config/install/user.role.contributor.yml
Add this:
dependencies: module: - yourmodule enforced: module: - yourmodule
For the Unit tests, you could do something like
/** * Tests module uninstallation, and reinstallation. */ public function testInstallUninstallReinstallModule() { // Ensure that the module can be installed. \Drupal::service('module_installer')->install(['form_mode_manager_examples']); $this->assertFalse(\Drupal::moduleHandler()->moduleExists('form_mode_manager_examples'), 'The module has been installed.'); // Uninstall the module. \Drupal::service('module_installer')->uninstall(['form_mode_manager_examples']); $this->assertFalse(\Drupal::moduleHandler()->moduleExists('form_mode_manager_examples'), 'The module has been uninstalled.'); // Reinstall the module. \Drupal::service('module_installer')->install(['form_mode_manager_examples']); $this->assertTrue(\Drupal::moduleHandler()->moduleExists('form_mode_manager_examples'), 'The module has been reinstalled.'); }
- Status changed to Needs work
about 1 year ago 5:43am 7 November 2023 - π¦πΊAustralia elc
Maybe to the test - it's a very much known thing that removing config values works, and that they are the only thing standing in the way of installing the module. Yes it's a bug, but it doesn't really need a test as going forward it won't happen again unless more config items are added to example (unlikely at this point) and it is forgotten to add them to uninstall function. Maybe a test really is needed for that rare occurrence.
And should also have a hook_update_N on form_mode_manager to remove the left over config if the example module is not installed and those config items still exist in a site. Unless of course someone uses those bits of config in a production site!
Perhaps not automatic, but a hook_requirements warning linking to a form which allows the admin to remove them manually if they choose, or continue to keep them in the site. What are the chances that someone built a production site based on an example module?
If that enforced module dependency works, that's probably a better long term solution, but it's not going to help anyone who installed the config before such a change, so the hook_uninstall method will need to be included unless there is a way to add that to the config items.
NW to add module dep at least.
- π¨π¦Canada adriancid Montreal, Canada
I think we should handle this in two ways, because why we need a hook_unistall when you can enforce in the configuration files the removal of the configs?
So what I'm proposing is handle here the uninstall of the existing configurations if the module is installed using a hook_update. We should add to the configurations the dependency, and in π Enforce the configurations to be uninstalled at the same time as the example module Active enforce the configurations to be uninstalled once the module is uninstalled from the site.