5

I have installed Drupal 8.6.3 minimum profile and found out that there's no Administrator role under permissions section. Is this normal or am I missing something?

We have few people that needs to be using Admin roles, so without a Administrator role, I can't assign them to such a role.

enter image description here

3
  • 1
    @see Document difference between "standard" and "minimal" core install profiles which I found after googling for: drupal minimal profile administrator role.
    – leymannx
    Jan 22, 2019 at 7:31
  • Thanks for the answer @leymannx Can't I just create the Administrator role without reinstalling a standard profile as I have already in the middle of the project? Jan 22, 2019 at 7:42
  • I'd say so. But better try it out yourself. Dump your current database. Then try it out. If it's not working as expected drop the database and reimport the previously dumped database.
    – leymannx
    Jan 22, 2019 at 7:55

1 Answer 1

18

Yes, that is expected, since the Minimal profile creates less entities than the Standard profile. You can see that by comparing the config/install directory in the first profile with the config/install directory in the latter profile.

As per creating the role from the user interface, that would be possible, but the created role would be a role like the others, while the Administrator role created from the Standard profile automatically gets all the permissions defined in a Drupal site. In fact, Role::hasPermission() uses the following code.

  if ($this->isAdmin()) {
    return TRUE;
  }
  return in_array($permission, $this->permissions);

For the Administrator role, $this->isAdmin() always return TRUE; for every role you create from the user interface, $this->isAdmin() would return FALSE.

If you need that role, and you cannot reinstall Drupal using the Standard profile, you can create a custom module, for which you create a config/optional/user.role.administrator.yml file with the following content.

langcode: en
status: true
dependencies:
  enforced:
    module:
      - yourmodule
id: administrator
label: Administrator
weight: 2
is_admin: true
permissions: {  }

(Replace yourmodule with the module name.)

When the module is installed, the role will be created. Since the file contains is_admin: true, the role will have all the permissions, automatically, like the Administrator role created by the Standard profile.

The alternative method that doesn't involve writing modules is importing the user.role.administrator.yml file in the site. The content of the file is similar to the content of the file I previously suggested, with the exception that there aren't dependencies.

langcode: en
status: true
dependencies: {  }
id: administrator
label: Administrator
weight: 2
is_admin: true
permissions: {  }

I would use the custom module method if there are other entities/bundles that you normally create when installing Drupal for a new site.
If instead you don't have the need to create other entities/bundles, importing a single file is quicker.

If you installed Drush, with drush config-edit user.role.administrator you can edit that file and set is_admin to true.

7
  • 2
    Very profound answer. Another option to create the role would be to import the YAML code in UI here: admin/config/development/configuration/single/import
    – 4uk4
    Jan 22, 2019 at 10:11
  • What about: drush role-create 'administrator' 'Administrator'
    – rebeling
    Feb 8, 2019 at 22:55
  • @rebeling I am not sure it works, if role-create doesn't have a flag that sets is_admin to TRUE. The role name doesn't have a particular meaning; otherwise, Drupal 8 won't use is_admin.
    – apaderno
    Feb 9, 2019 at 8:17
  • 1
    ha, just changed the yaml for this role is_admin from null to true and imported the config ...the role is_admin now. thx
    – rebeling
    Feb 9, 2019 at 18:53
  • Thanks @rebeling, I found the yaml config in web/core/profiles/standard/config/install/user.role.administrator.yml and imported it. Worked perfect. @klamlaluno, I'd suggest adding that method to your answer. :)
    – David R.
    Oct 27, 2019 at 2:04

Your Answer

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

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