Unable to install Form Mode Manager examples. Already exists in active configuration

Created on 22 June 2022, over 2 years ago
Updated 6 March 2024, 10 months ago

Problem/Motivation

I have installed the Form Mode Manager examples, on uninstall the module and install it again.
The following error message shows up.

Unable to install Form Mode Manager examples, core.entity_form_display.node.node_form_mode_example.contributor, core.entity_form_display.node.node_form_mode_example.default, core.entity_form_mode.node.contributor, core.entity_view_display.node.node_form_mode_example.default, core.entity_view_display.node.node_form_mode_example.teaser, field.field.node.node_form_mode_example.body, field.field.node.node_form_mode_example.field_picture, field.storage.node.field_picture, node.type.node_form_mode_example, user.role.contributor already exist in active configuration.

Proposed resolution

- Delete examples after uninstall.

πŸ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡ΈπŸ‡¦Saudi Arabia abdulaziz zaid Riyadh

Live updates comments and jobs are added and updated live.
  • Needs manual testing

    The change/bugfix cannot be fully demonstrated by automated testing, and thus requires manual testing in a variety of environments.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡Έ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
  • πŸ‡ΊπŸ‡Έ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
  • πŸ‡¦πŸ‡Ί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.

Production build 0.71.5 2024