I have a custom variable in one of my modules and I want to be able to give permission to that variable to a specific role on my site.

I have the hook_permission function setup and I can see it in the admin/people/permissions interface, but I'm not sure how to implement a hook or whatever to give the user access to admin/config/system/variable/edit/my_custom_variable

  • I don't have "variable" in my "admin/config/system" path. What module are you using to provide direct variable editing capabilities?
    – Mołot
    Oct 1, 2013 at 13:07
  • He's using the variable drupal.org/project/variable module.
    – Steven
    Oct 1, 2013 at 13:09

2 Answers 2


One method would be to use something like https://drupal.org/project/config_perms to add a custom permission to the admin/config/system/variable/edit/my_custom_variable path. You can then use this custom permission to grant access to it.


In hook_menu we have:

$items['admin/config/system/variable/edit/%'] = array(
  'title' => 'Edit variable',
  'page callback' => 'drupal_get_form',
  'page arguments' => array('variable_edit_form', 5),
  'access callback' => 'variable_access',
  'access arguments' => array(5),

Now, what's 'access callback'? By the API:

"access callback": A function returning TRUE if the user has access rights to this menu item, and FALSE if not. It can also be a boolean constant instead of a function, and you can also use numeric values (will be cast to boolean). Defaults to user_access() unless a value is inherited from the parent menu item; only MENU_DEFAULT_LOCAL_TASK items can inherit access callbacks. To use the user_access() default callback, you must specify the permission to check as 'access arguments' (see below).

So the module is using function variable_access($variable, $account = NULL) defined in the main variable.module. Now, this function uses data provided by function variable_get_info($name = NULL, $options = array()), that collects it's data from modules that implements hook_variable_info().


In hook_variable_info() when defining your variable, set 'access' to an existing permission, or permission your module provides. Then simply give that permission to user roles that should be able to edit variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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