Drupal Answers Asked by Pan Chrono on August 4, 2020
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
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.
Answered by Patrick Kenny on August 4, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP