User Role creation in module overridden by configuration import

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

One Answer

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

Add your own answers!

Related Questions

Undefined function in module

0  Asked on December 19, 2021 by idjit


How to get group id from custom url

1  Asked on December 17, 2021 by leopathu


Some fields are not sorting properly in view

1  Asked on December 17, 2021 by weblink


Drush Hangs on wget but wget Works

1  Asked on December 14, 2021 by marshmellow1328


How to get menu title inside menu–main.html.twig file

1  Asked on December 14, 2021 by siddiq


hook_form_alter add field after submit button to exposed view

1  Asked on December 14, 2021 by user7355700


Images uploaded with CKeditor disappear after cron run

1  Asked on December 12, 2021 by alexander-kim


How have multiple instances of a Custom Block?

2  Asked on December 10, 2021 by jagmitg


Node view mode in page template suggestions

1  Asked on December 10, 2021 by sarah-c


How to sort translation under Translate tab?

1  Asked on December 10, 2021


Migration with default values in the yml file

1  Asked on December 10, 2021 by webuser57


menu_get_active_trail returns page not found

1  Asked on December 8, 2021 by jurgenr


hook_field_formatter_view does not get called

1  Asked on December 8, 2021 by alexei-rayu


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP