Friday, August 17, 2012

What is the difference between page callback and access callback


  • 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/bazbaz 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.

No comments:

Post a Comment

only show translated menu items into current language (Drupal 8)

function MY_THEME_preprocess_menu(&$variables) {   if ($variables['menu_name'] == 'brancott-header-menu') {    $langu...