For a module I'm making, I want to have it so only roles I set can have access to it. When I go into the permissions section however, no checkboxes appear next to my module (they do for all the other modules though). Am I setting this incorrectly?

Here is my code:

function editslideshows_menu() {
  return array('editslideshows.html' => array(
      'title' => 'Edit Slideshows',
      'description' => 'Edit Slideshows',
    'access callback' => 'user_access',
    'access arguments' => array('administer users'),
	'page callback' => 'editslideshows_all',
      'page arguments' => array('access content')
      
    )
  );

Anybody know what I'm doing wrong?

Comments

yuriy.babenko’s picture

Did you implement hook_perm() ?

Next time please use <?php ?> tags around your code.

---
Yuriy Babenko
www.yubastudios.com
My Drupal tutorials: http://yubastudios.com/blog/tag/tutorials

---
Yuriy Babenko | Technical Consultant & Senior Developer
http://yuriybabenko.com

lyricnz’s picture

The way it works is this:

- your module can define new permissions by implementing hook_perm. This just adds a new permission, defined by a bit of text. See sample code at the bottom of this comment for an example.

- your menu entry can check for this by using the 'access callback' and 'access arguments'. settings within the menu item. The first one says what function to call to check access control (this defaults to user_access()). The second one says what parameters should be passed to this function. If you just pass a set of permissions, user_access() checks against the current user, and returns TRUE if the user is allowed to access your content.

- 'page arguments' are parameters that are passed to 'page callback' (which is the function that actually generates your HTML). You probably don't want the one your coded included.

- it's a little unusual to use the "editslideshows.html" path for your menu entry, but that's entirely up to you. Most people would use something like "editslideshows"

- your code should probably look something like this:

function editslideshows_perm() {
  return array('edit slideshows');
}

function editslideshows_menu() {
  $items['editslideshows.html'] = array(
    'title' => 'Edit Slideshows',
    'page callback' => 'editslideshows_all',
    'access callback' => 'user_access',
    'access arguments' => array('edit slideshows'),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

See http://drupal.org/node/109157 for a discussion of access control (in Drupal 6)

smithaa02’s picture

Thanks lyricnz...that worked exactly how I needed it to.