hook_permission() is a handy way to allow certain roles to access certain pages, i.e. the 'Administrator' to change settings and say 'Comms Team' to view the results. As per a lot of Drupal building the return value must be a nested array, and that can be tricky to remember... So here is an example.
/** * Implementation of hook_permission(). */ function MY_MODULE_NAME_permission() { return array( 'view MY_MODULE_NAME' => array( 'title' => t('View MY_MODULE_NAME'), 'description' => t('Allow certain roles to view MY_MODULE_NAME without control of the settings.'), ), 'administer MY_MODULE_NAME' => array( 'title' => t('Administer MY_MODULE_NAME'), 'description' => t('Add, delete and edit the settings for MY_MODULE_NAME.'), ), ); }
Simply replace MY_MODULE_NAME with the 'machine' name of your module.
Text that appears inside the t() function can be a 'real' name rather than the 'machine' name as this is just text to be displayed on the 'permissions' page.
Main Category