Can anyone please explain with example for difference between page callback and access callback in drupal?

  • page_callback is a function called which will be used to generate contents of the page
  • access_callback is a function called which will be used determine if a user has access to view the page. This can be used where a simple permission isn't enough. An example would be that the author of the node would be allowed to edit the node or any user with a special admin permission.
    Note the access_callback will by default be the user_access function which will check that the user has a specific permission.

Both of these keys have a sidekick, [page/access] arguments which should be an array of arguments that is passed to the function. arguments can either be static or you can use numbers to reference the URL. If a load function us used on a URL arg, like %user, referencing it will yield the return of the load function, like the user object instead of the user id (uid).

Page callbacks will receive any URL args that aren't used for pattern matching. So if you define an URL foo/bar and user goes to foo/bar/baz, baz will be added to the list of args passed to the page callback. This can be handy in some cases where you can provide a default argument that can be overridden in the URL.

If in doubt always check the api refference api.drupal.org

  • 1
    There is always a access callback function, by default it is user_access() and the argument passed to it is a permission. I remember that I found it initially confusing that the permission is an array but you can only specify a single permission. Maybe you could clarify that part a bit :) – Berdir Jun 15 '11 at 11:09

Page callback: a function that is responsible to provide html for the page e.g.

function get_html(){
    return "<html>";

or drupal_get_form() if page is generation a form. In this case 'page arguments' are required to link form defining callback with it.

Access callback: A function that is responsible to check a user has access on the content of this page callback.

normally it is user_access()

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.