You are here

function uc_addresses_render_link in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 uc_addresses.pages.inc \uc_addresses_render_link()

Renders a link to an address if the user has access to the given operation of the address.

@todo Maybe move this to module file? @todo Good for views address links too?

Parameters

UcAddressesAddress $address: An instance of UcAddressesAddress.

string $op: The type of link to render: 'view', 'edit' or 'delete'.

array $options: (optional) A list of options to pass to l().

Return value

string The rendered link or an empty string if the user has no access.

1 call to uc_addresses_render_link()
template_preprocess_uc_addresses_list_address in ./uc_addresses.pages.inc
Prepares variables for one address.

File

./uc_addresses.pages.inc, line 255
Page callbacks for viewing, adding, editing, and deleting addresses.

Code

function uc_addresses_render_link(UcAddressesAddress $address, $op, $options = array()) {
  $address_user = user_load($address
    ->getUserId());
  $uri = $address
    ->uri();
  switch ($op) {
    case 'view':
      if (!UcAddressesPermissions::canViewAddress($address_user, $address)) {
        return '';
      }
      $title = t('View address');
      $path = $uri['path'];
      break;
    case 'edit':
      if (!UcAddressesPermissions::canEditAddress($address_user, $address)) {
        return '';
      }
      $title = t('Edit address');
      $path = $uri['path'] . '/edit';
      break;
    case 'delete':
      if (!UcAddressesPermissions::canDeleteAddress($address_user, $address)) {
        return '';
      }
      $title = t('Delete address');
      $path = $uri['path'] . '/delete';
      break;
  }

  // Add CSS classes to the link.
  $classes = array(
    'address-link',
    $op . '-address-link',
  );
  if (!isset($options['attributes']['class'])) {
    $options['attributes']['class'] = array();
  }
  $options['attributes']['class'] = array_merge($options['attributes']['class'], $classes);
  return l($title, $path, $options);
}