0

I'm creating a user Role in a .yml file like user.role.myrole.yml. This works fine when this module is installed manually and the Role is created.

When I enable this module via configuration import though, only the roles defined in this configuration set are installed and not what is in the config/install folder of that module.

Tried putting that file in config/optional folder and writing a hook_install() for the user creation also with the same results.

I would like to have this only in the module, the module may or not be installed via config, so I need this role only when this module is enabled. How can this be achieved?

Thank you

4
  • Module need to be enabled explicitly, enabling it via config import doesnt install it cleanly. You need to install the module to get its functionality reflected. Jul 30, 2020 at 8:37
  • 1
    I don't think the above is valid. When a module is enabled via configuration it does get installed.
    – Pan Chrono
    Jul 31, 2020 at 6:15
  • if the module is enabled/disabled via config split will it execute hook_install or hook_uninstall will get executed ? because for me they havent got executed tried multiple times. Either i need to install or uninstall module again. Aug 3, 2020 at 7:22
  • I dont understand what config split means :)
    – Pan Chrono
    Aug 3, 2020 at 9:20

1 Answer 1

1

Docs for installing default configuration in a custom module

However, putting a role in the configuration of a module is probably a bad idea. I can't think of an example of a major contrib module that does this.

Imagine this situation: you install the module, and then the role gets enabled. Next, the user adds some other permissions to the role (created by the module) unrelated to your module. Then the user uninstalls the module. Now what should happen? Usually, the expectation is that module config will be cleaned up on uninstall, but this won't happen for roles.

What you probably want to do is add some permissions and allow the user of the module to add those to the role of the user's choice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.