function commerce_addressbook_entity_view in Commerce Addressbook 7.3
Same name and namespace in other branches
- 7.2 commerce_addressbook.module \commerce_addressbook_entity_view()
Implements hook_entity_view().
Adds the "edit", "delete" and "set as default" links to the customer profile.
File
- ./
commerce_addressbook.module, line 440 - Defines addressbook functionality for customer profiles, allowing them to be reused and managed on a per-user basis.
Code
function commerce_addressbook_entity_view($entity, $type, $view_mode, $langcode) {
if ($type != 'commerce_customer_profile' || $view_mode != 'addressbook') {
return;
}
$links = array();
global $user;
if (commerce_customer_profile_access('update', $entity)) {
$default_profile_id = commerce_addressbook_get_default_profile_id($user->uid, $entity->type);
drupal_add_library('system', 'drupal.ajax');
if (!$default_profile_id || $default_profile_id != $entity->profile_id) {
$links['default'] = array(
'#theme' => 'link',
'#text' => t('set as default'),
'#path' => 'user/' . $entity->uid . '/addressbook/' . $entity->type . '/default/' . $entity->profile_id . '/nojs',
'#options' => array(
'attributes' => array(
'class' => array(
'use-ajax',
),
),
'html' => FALSE,
),
);
}
$links['edit'] = array(
'#theme' => 'link',
'#text' => t('edit'),
'#path' => 'user/' . $entity->uid . '/addressbook/' . $entity->type . '/edit/' . $entity->profile_id,
'#options' => array(
'attributes' => array(),
'html' => FALSE,
),
);
}
if (commerce_customer_profile_access('delete', $entity)) {
$links['delete'] = array(
'#theme' => 'link',
'#text' => t('delete'),
'#path' => 'user/' . $entity->uid . '/addressbook/' . $entity->type . '/delete/' . $entity->profile_id,
'#options' => array(
'attributes' => array(),
'html' => FALSE,
),
);
}
if ($links) {
// Add suffixes for each link except the last one.
$last_link = end($links);
foreach ($links as $key => $link) {
if ($last_link !== $link) {
$links[$key]['#suffix'] = ' | ';
}
}
$entity->content['commerce_addressbook_options'] = array_merge(array(
'#weight' => 100,
'#prefix' => '<div class="addressbook-links">',
'#suffix' => '</div>',
), $links);
}
}