Nov 9, 2014

hook_permission() has disappeared

As of Beta 1 and possibly a bit earlier, hook_permission() is gone. In its place, there is yet another YAML file.

Drupal 7 optimizely.module file,

  function optimizely_permission() {
    return array(
      'administer optimizely' => array(
        'title' => t('Administer Optimizely module'),
        'description' =>
          t('Administer access to everything in module'),
        'restrict access' => TRUE,
      ),
    );
  }


Drupal 8 optimizely.permissions.yml file,

  administer optimizely:
    title: 'Administer Optimizely module'
    description: 'Administer access to everything in module'
    restrict access: true


Exactly the same pieces of information are provided in the new definition as in the old. However, there are no calls to the t() function for translation purposes. In the source article, there is a comment that "We can then make sure static permissions run strings through t()", so it sounds like the intent is for t() to be called automatically as part of the processing of the file.

Obsolete post on hook_permission() is at http://optimizely-to-drupal-8.blogspot.com/2014/05/hookpermission-is-same-as-in-d7.html

Sources:

Defining permissions via $module.permissions.yml
https://www.drupal.org/node/2311427

No comments:

Post a Comment