1

I have implemented a hook_menu method in a module i'm writing.

The problem i'm facing is, i'm not able to pass an access argument that grants access to all the administrators.

The only one able to access the page is the admin account that was made upon installation.

Any help would be appreciated. This is the code.

function raffle_menu()
{
    $items = array();

    $items['admin/config/people/raffle'] = array(
        'title' => 'Raffle',
        'access callback' => 'user_access',
        'access arguments' => array('administer site configuration'),
        'file' => 'raffle_admin.inc',
        'page callback' => 'raffle_abc_view',
    );
    return $items;
}
5
  • have you defined raffle_permission function in your module? – Shabir A. Jan 14 '16 at 19:56
  • oops. No, i didn't know that was necessary. – Haider Ali Jan 14 '16 at 19:57
  • Yes, It is necessary! – Shabir A. Jan 14 '16 at 20:07
  • @ShabirA. I used the hook_permissions hook, and enabled that permission for all my administrators. If i'm correct, now i just pass that permission to the access argument? – Haider Ali Jan 14 '16 at 20:09
  • see my answer. and yes! – Shabir A. Jan 14 '16 at 20:11
2

Defining your module in hook_menu is not enough. You need to define hook_permission() too. You can do something like this

function raffle_permission() {
   return array(
    'administer site configuration' => array(
      'title' => t('Administer Site Configuration'),
      'description' => t('Perform administration tasks for my module.'),
    ),
  );
}
0

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.