Roles and permissions under the hood

Roles are configuration entities (user_role) represented by the Role entity type class. So, they can be created through the UI and exported as configuration to be available on all the environments. As such, there is not much you need to do in your code to define a role, but simply create them as needed in the UI and export them to configuration. As you remember, if you want your role to be provided by your module, add the exported YAML file to the config/install folder (and remove the UUID). Refer to Chapter 6, Data Modeling and Storage, for more information.

Permissions, on the other hand, are a custom construct. They used to be defined by implementing hook_permissions(), but are created using a YAML ...

Get Drupal 8 Module Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.