May 22, 2014

hook_permission() is the same as in D7

hook_permission() in Drupal 8 has not changed and can be implemented in the .module file as in D7.
function optimizely_permission() {
  return array(
    'administer optimizely' => array(
      'title' => t('Administer Optimizely module'),
      'description' =>
        t('Administer access to everything in module'),
      'restrict access' => TRUE,
What's different is that the permissions defined in hook_permission() are then used in the  .routing.yml  file to control access to specific paths. For instance,
  path: /admin/config/system/optimizely

  # ...
    _permission: administer optimizely

Update for Drupal 8, beta 1: hook_permission() has been removed. Its functionality is now provided by the .permissions.yml file. See


DRUPAL 8 INFO HOOK TO PLUGIN, DrupalCon Prague, Sept 2013

This presentation states: "Info hooks that simply return a data array - like hook_permission() - without associated functionality - are not candidates to become plugins." I take this to mean that these kinds of hooks will largely remain unchanged.

No comments:

Post a Comment