I’m creating a user Role in a .yml file like
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?
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.
Answered by Patrick Kenny on August 4, 2020
1 Asked on December 19, 2021 by arcy
1 Asked on December 17, 2021
5 Asked on December 14, 2021
1 Asked on December 14, 2021 by siddiq
1 Asked on December 14, 2021 by user7355700
1 Asked on December 12, 2021 by alexander-kim
1 Asked on December 12, 2021 by aaron-s
4 Asked on December 12, 2021
1 Asked on December 12, 2021 by vanessa-abi-rashed
1 Asked on December 10, 2021 by jessica-ix
Get help from others!