function payment_method_access in Payment 7
Check if a user has access to perform a certain payment method operation.
Parameters
string $operation: One of the following operations:
- "create" (requires $payment_method)
- "update" (does not require $payment_method, but only grants access if the user has permission to update any payment method)
- "delete" (does not require $payment_method, but only grants access if the user has permission to delete any payment method)
- "view" (does not require $payment_method, but only grants access if the user has permission to view any payment method)
- "enable" (requires $payment_method)
- "disable" (requires $payment_method)
- "clone" (requires $payment_method)
PaymentMethod $payment_method: The payment method the user wants to perform the operation on.
object $account: The user account for which to check access. If NULL, the current user is used.
Return value
boolean
See also
5 calls to payment_method_access()
- payment_form_payment_method in ./
payment.ui.inc - Implements form build callback: the payment method add/edit form.
- payment_method_access_token in ./
payment.module - Check if a user has access to perform a certain payment method operation and do additional token validation.
- payment_method_form_add_access in ./
payment.ui.inc - Menu access callback for payment_method_form_add().
- payment_page_payment_method_add_select_controller in ./
payment.ui.inc - Shows a page with controllers payment methods can be added for.
- payment_page_payment_method_add_select_controller_access in ./
payment.ui.inc - Menu access callback for payment_page_payment_method_add_select_controller().
3 string references to 'payment_method_access'
- PaymentTestPaymentMethodEntityPermissionWebTestCase::testPaymentMethodEntityPermissions in tests/
payment_test/ tests/ PaymentTestPaymentMethodEntityPermissionWebTestCase.test - payment_entity_info in ./
payment.module - Implements hook_entity_info().
- payment_menu in ./
payment.module - Implements hook_menu().
File
- ./
payment.module, line 1006 - Hook implementations and shared functions.
Code
function payment_method_access($operation, PaymentMethod $payment_method = NULL, $account = NULL) {
global $user;
// Default to the currently logged-in user.
if (!$account) {
$account = $user;
}
switch ($operation) {
case 'create':
return $payment_method && user_access('payment.payment_method.create.' . $payment_method->controller->name, $account);
case 'enable':
return $payment_method && $payment_method->enabled == FALSE && payment_method_access('update', $payment_method, $account);
case 'disable':
return $payment_method && $payment_method->enabled == TRUE && payment_method_access('update', $payment_method, $account);
case 'clone':
return payment_method_access('create', $payment_method, $account) && payment_method_access('view', $payment_method, $account);
case 'view':
case 'update':
case 'delete':
return user_access('payment.payment_method.' . $operation . '.any', $account) || $payment_method && user_access('payment.payment_method.' . $operation . '.own', $account) && $payment_method->uid == $account->uid;
}
return FALSE;
}