based on some condition i want to give access to a module.
if(abc == abc) {
//give access to module xyz.
}
based on some condition i want to give access to a module.
if(abc == abc) {
//give access to module xyz.
}
There's no such concept as giving access to a whole module in Drupal, only pages that a module would define. Usually this is done by implementing hook_menu()
to define the page(s) and then providing either an access callback
or access arguments
.
The first defines a function that will be called to make your access decision:
function mymodule_menu() {
$items['some/path'] = array(
'title' => 'Some Title',
'page callback' => 'mymodule_callback',
'access callback' => 'mymodule_some_path_access'
);
return $items;
}
function mymodule_some_path_access() {
global $user;
if ($user->foo == 'bar') {
// Access allowed, return TRUE
return TRUE;
}
// Access not allowed, return FALSE
return FALSE;
}
The second defines arguments that will be passed to the user_access
function. This will usually be based on permissions your module provides:
function mymodule_menu() {
$items['some/path'] = array(
'title' => 'Some Title',
'page callback' => 'mymodule_callback',
'access arguments' => array('access mymodule')
);
return $items;
}
function mymodule_perm() {
return array(
'access mymodule'
);
}
In the second example a user will be denied access unless they have the permission 'access mymodule' (as defined in the permissions admin area of Drupal).
Hope that helps