I have a custom module and with hook_permission() I create module's specific permissions. Is there a hook (hook_role_permission) in which I can create a module specific role and assign it's permissions?

I don't want to put these in custom_module.install file because I don't want to reinstall the whole website.

  • 2
    Please check this link it has a good description drupal-solutions.com/… – Mohammed Shameem Jan 24 '13 at 15:18
  • Thanks. But I'm don't know exactly where should I write that code? In hook_permission or is there any other hook? – bogtan Jan 24 '13 at 15:22

You don't need to re-install the whole website just to make a change to your .install file...you can just implement hook_update_N() instead.

 * Description of the update.
function MYMODULE_update_7100() {
  // Perform some tasks. From the comments it looks like you have the logic you need.

  return t('Tasks completed');

After adding that code visit update.php and follow the instructions (or run drush updatedb) to update the database.

The changes will then be applied, without having to reinstall your modules.

This hook is the best place for your code in this situation (in my opinion) as it will only need to be run once. The update system will make sure of that on your behalf, and if you need to make further changes you can just add another update function.

Please make sure you read through the docs fully before giving it a go, there are some caveats that you really should know. Basic stuff but quite important

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.