How to add Custom Permissions to your Drupal 8 module

In order to add custom permissions we used to use hook_permission in Drupal 7, however in Drupal 8 this is done through the yourmodulename.permissions.yml file

Here is an example of what the file should look like

administer commerce_amazon_slider:
  title: 'Administer Commerce Amazon Slider'
  description: 'View, edit and update Commerce Amazon Slider configurations'

After you add this file with the customn permissions you need, clear the cache then navigate to YourSiteName.com/admin/people/permissions to view the new permissions

Thank you and looking forward to help you do more with Drupal

Share this post