Defining permissions

The way to create permissions in a custom module is by creating a *.permissions.yml file and adding the definitions in there. Consider the following example:

administer my feature:
  title: 'Administer my feature'
  restrict access: true

In this example, administer my feature is the machine name of the permission and actually the most important part. This is what you will use in your code to reference it. Then, we have a title that shows up on the permissions management page we saw earlier. Finally, we have a restrict access key by which we can specify whether we need a warning to be output on the permissions management page regarding the security implications, as follows--Warning: Give to trusted roles only; this permission ...

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.