Path Registration Parameters

There are a couple of other entries that can be set for a menu item. The Drupal API documents all recognized keys: http://api.drupal.org/ api/function/hook_menu/6.

In order to pass arguments to the callback function, we set the page arguments entry: 'page arguments' => array(3). Page arguments takes an array of arguments. In our case, the array will have only one member: 3. What does this do? Let's take a look at the path again, as it would appear in the query string of a URL:

q=admin/emailusers/compose/1

As I mentioned earlier, this path appears to Drupal as four parameters: admin, emailusers, compose, and (in this case) 1. This last value indicates that we are dealing with the user whose User ID is 1.

Each of these parameters is associated with a number in ascending order from left to right. Thus, admin is 0, emailusers is 1, compose is 2, and the value of the placeholder (the User ID 1) is 3.

To pass the placeholder to the page callback function, then, we reference it by number. Thus 'page arguments' => array(3) directs Drupal to pass the value of the fourth item in the URI (the placeholder) as an argument to the emailusers_ compose() function.

The next line controls page access:

'access arguments' => array('administer users'),

We glanced at access arguments in the last chapter. It plays a more important role here, so we will look at it in more detail.

This entry tells the Drupal menu system who should have rights to access this page. The value of the argument is an array of permissions strings.

Permissions strings are managed through the administration pages. You can access them through Home | Administer | User management | Permissions. According to our access arguments, our new page should be accessible to any user with administer users permissions.

Looking at the Permissions page in User management, we can see what Drupal roles have this level of permissions:

Permission anonymous authenticated site

J

user

user

administrators

revert revisions

r

r

r

view revisions

r

r

r

system module

access administration pages

r

r

r

administer actions

r

r

r

administer files

r

r

r

administer site configuration

r

r

r

select different theme

r

r

r

taxonomy module

administer taxonomy

r

r

r

user module

access user profiles

r

r

r

administer permissions

0 0

Post a comment