Views Access Callback module provides callback-based access control for Views.
Available callback functions are defined by modules using hook_views_access_callbacks()
function, then could be set in in view's Access restrictions configuration.
Example hook_views_access_callbacks()
implementation:
Drupal 6
In Drupal 6 you simply return a flat array of access callback function names:
/**
* Implementation of hook_views_access_callbacks().
*/
function MYMODULE_views_access_callbacks() {
return array(
'MYMODULE_user_has_access',
);
}
Drupal 7
In Drupal 7 you should return a keyed array instead, where the key is the callback function name and the value is a human readable function description:
/**
* Implementation of hook_views_access_callbacks().
*/
function MYMODULE_views_access_callbacks() {
return array(
'MYMODULE_user_has_access' => t('My access check function'),
);
}
Callback functions -Drupal 6 and Drupal 7
Your callback functions should return either TRUE (if access should be granted) or FALSE (if access should be forbidden).
If the view has arguments defined, their values will be passed as callback function parameters.
function MYMODULE_user_has_access($arg1 = NULL, ...) {
if ( ... ) {
return TRUE;
}
return FALSE;
}
Note that users with access all views permission can see any view, regardless of any other permissions.