The idea I borrowed from the profile_role module:
function user_types_enabled_categories_raw($user_id) {
global $user;
static $categories;
if (!isset($categories[$user_id])) {
$categories[$user_id] = array();
$query = "SELECT DISTINCT category
FROM profile_fields pf INNER JOIN user_types_profile_fields upf ON pf.fid=upf.fid
WHERE enabled=1 AND upf.user_type_id=%d";
$user_type_id = user_types_user_user_type_id($user_id);
$result = db_query($query, $user_type_id);
while ($category = db_result($result)) {
$categories[$user_id][] = $category;
}
}
return $categories[$user_id];
}
/**
* Implementation of hook_menu_alter().
*/
function user_types_menu_alter(&$callbacks) {
$result = db_query('SELECT DISTINCT(category)
FROM {profile_fields}');
while ($category = db_result($result)) {
$key = 'user/%user_category/edit/' . $category;
$callbacks[$key]['access callback'] = 'user_types_access_category';
$callbacks[$key]['access arguments'] = array(1, $category);
}
}
/**
* Access callback -- ensure that the user being editted is of a type that
* uses the field category, if so then ensure that the editting user has
* permission to edit the fields.
*
* @param object $user User being editted.
* @param string $category Profile field category.
* @return boolean Access.
*/
function user_types_access_category($user, $category) {
$enabled_categories = user_types_enabled_categories_raw($user->uid);
if (!in_array($category, $enabled_categories)) {
return FALSE;
}
else {
return user_edit_access($user);
}
}
Great module though!
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | user_types_805612.patch | 1.83 KB | pvasener |
Comments
Comment #1
buzzman commentedThis sounds gr8 ...
Can you provide some directions (and maybe even a patch) on how to go about incorporating the snippets correctly. It wud be also nice to know if this has been tested and if there are any potential code clash(s) that one should be aware of while adding this code ...
Thanks in any case.
Comment #2
pvasener commentedI confirm this is a great & functional way to hide the tabs. Here is a patch ready to be committed.
@buzzman: To apply this patch, download it in the module directory and run the following command:
patch -p0 < user_types_805612.patch