function commerce_addressbook_entity_view in Commerce Addressbook 7.2
Same name and namespace in other branches
- 7.3 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 200 - 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') {
$links = array();
global $user;
if (commerce_addressbook_profile_access('update', $entity)) {
static $record;
if (empty($record) || $record->uid != $user->uid || $record->type != $entity->type) {
$query = db_select('commerce_addressbook_defaults', 'cad')
->fields('cad')
->condition('uid', $entity->uid)
->condition('type', $entity->type)
->execute();
$record = $query
->fetchObject();
}
drupal_add_library('system', 'drupal.ajax');
if (empty($record) || $record->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,
),
'#suffix' => ' | ',
);
}
$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,
),
'#suffix' => ' | ',
);
}
if (commerce_addressbook_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) {
$entity->content['commerce_addressbook_options'] = array_merge(array(
'#weight' => 100,
'#prefix' => '<div class="addressbook-links">',
'#suffix' => '</div>',
), $links);
}
}
}