contact_permissions.module in Contact Permissions 7
Same filename and directory in other branches
Provides permissions for having a personal contact form
File
contact_permissions.moduleView source
<?php
/**
* @file
* Provides permissions for having a personal contact form
*/
/**
* Implements hook_permission().
*/
function contact_permissions_permission() {
return array(
'have a personal contact form' => array(
'title' => t('Have a personal contact form'),
'description' => t('Allow users to have a personal contact form based in their permissions.'),
),
);
}
function contact_permissions_check_access($account) {
return user_access('have a personal contact form', $account);
}
/**
* Implements hook_menu_alter().
*/
function contact_permissions_menu_alter(&$items) {
$items['user/%user/contact']['access callback'] = '_contact_permissions_user_tab_access';
}
/**
* Menu access callback for a user's personal contact form.
*
* @param $account
* A user account object.
* @return
* TRUE if the user is allowed to have a contact form
* or FALSE otherwise.
*/
function _contact_permissions_user_tab_access($account) {
// Check core's contact access callback first
$access = _contact_personal_tab_access($account);
if ($access) {
$access = contact_permissions_check_access($account);
}
return $access;
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Restricts the option of enabling/disabling his personal contact form.
* Based on permissions defined by this module.
*/
function contact_permissions_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
$account = $form['#user'];
$access = contact_permissions_check_access($account);
if (!$access) {
$form['contact']['#access'] = FALSE;
}
}
Functions
Name | Description |
---|---|
contact_permissions_check_access | |
contact_permissions_form_user_profile_form_alter | Implements hook_form_FORM_ID_alter(). |
contact_permissions_menu_alter | Implements hook_menu_alter(). |
contact_permissions_permission | Implements hook_permission(). |
_contact_permissions_user_tab_access | Menu access callback for a user's personal contact form. |