You are here

function uc_addresses_entity_access in Ubercart Addresses 7

Access callback for address entity.

Parameters

string $op: The operation to check for:

  • create
  • update
  • view
  • delete

UcAddressesAddress $entity: (optional) The address entity to check access for.

object $account: (optional) The account to check access for. Defaults to the current logged in user.

Return value

boolean TRUE if access is granted. FALSE if access is denied. NULL in case an unknown operation is passed.

3 calls to uc_addresses_entity_access()
uc_addresses_handler_field_uc_addresses_link::render_link in views/uc_addresses_handler_field_uc_addresses_link.inc
Renders the link if the user may view the address.
uc_addresses_handler_field_uc_addresses_link_delete::render_link in views/uc_addresses_handler_field_uc_addresses_link_delete.inc
Renders the link if the user may delete the address.
uc_addresses_handler_field_uc_addresses_link_edit::render_link in views/uc_addresses_handler_field_uc_addresses_link_edit.inc
Renders the link if the user may edit the address.
1 string reference to 'uc_addresses_entity_access'
uc_addresses_entity_info in ./uc_addresses.module
Implements hook_entity_info().

File

./uc_addresses.module, line 696
Adds user profile address support to Ubercart.

Code

function uc_addresses_entity_access($op, $entity = NULL, $account = NULL) {
  if ($entity instanceof UcAddressesAddress) {
    $address = $entity;
    $address_user = user_load($address
      ->getUserId());
    switch ($op) {
      case 'create':
      case 'update':
        return UcAddressesPermissions::canEditAddress($address_user, $address, $account);
      case 'view':
        return UcAddressesPermissions::canViewAddress($address_user, $address, $account);
      case 'delete':
        return UcAddressesPermissions::canDeleteAddress($address_user, $address, $account);
    }
  }
  else {

    // If no entity is given, check address access for all.
    switch ($op) {
      case 'create':
      case 'update':
        return UcAddressesPermissions::canEditAll($account);
      case 'view':
        return UcAddressesPermissions::canViewAll($account);
      case 'delete':
        return UcAddressesPermissions::canDeleteAll($account);
    }
  }

  // All other cases are unknown.
  return NULL;
}