You may know how to define custom permission in drupal 7. We were using hook_permission() inside *.module file like below
function mycustommodule_permission() {
'administer mycustommodule coniguration' => array(
'title' => t('Administer My Custom module Configuration'),
'description' => t('Configure My Custom module settings.'),
'restrict access' => TRUE,
),
}
'administer mycustommodule coniguration' => array(
'title' => t('Administer My Custom module Configuration'),
'description' => t('Configure My Custom module settings.'),
'restrict access' => TRUE,
),
}
In drupal 8 we are following a different method. Instead of writing hook we can define user permissions inside mycustommodule.permissions.yml.
Create mycustommodule.permissions.yml file put it inside root of your module (here root of mycustommodule module). Define your custom permisson like below
administer mycustommodule coniguration:
title: 'Administer My Custom module Configuration'
description: 'Configure My Custom module settings.'
restrict access: true
title: 'Administer My Custom module Configuration'
description: 'Configure My Custom module settings.'
restrict access: true
Then you can use custom permission for routing like below
mycustommodule.settings:
path: '/admin/config/mycustommodule'
defaults:
_controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
_title: 'My Custom module'
requirements:
_permission: 'administer mycustommodule coniguration'
path: '/admin/config/mycustommodule'
defaults:
_controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
_title: 'My Custom module'
requirements:
_permission: 'administer mycustommodule coniguration'
Make sure you are not using tab instead of space inside *.yml files.