如何更改 commerce_addressbook_entity_view() 的输出

Events happening in the community are now at Drupal community events on www.drupal.org.
waveer's picture

使用commerce addressbook模块

想更改一些输出 我找到了负责输出的函数是这个:

<?php
/**
* Implements hook_entity_view().
*
* Adds the "edit", "delete" and "set as default" links to the customer profile.
*/
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', $user->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(
         
'#markup' => l(t('set as default'), 'user/' . $entity->uid . '/addressbook/' . $entity->type . '/default/' . $entity->profile_id . '/nojs', array('attributes' => array('class' => array('use-ajax')))),
         
'#suffix' => ' | ',
        );
      }
     
$links['edit'] = array(
       
'#markup' => l(t('edit'), 'user/' . $entity->uid . '/addressbook/' . $entity->type . '/edit/' . $entity->profile_id),
       
'#suffix' => ' | ',
      );
    }
    if (
commerce_addressbook_profile_access('delete', $entity)) {
     
$links['delete'] = array('#markup' => l(t('delete'), 'user/' .$entity->uid. '/addressbook/' . $entity->type . '/delete/' . $entity->profile_id));
    }
   
$entity->content['commerce_addressbook_options'] = $links;
  }
}
?>

想对其中$links['edit']和$links['delete']做修改,应该怎么做
是不是用hook_entity_view_alter()函数
如果是 具体应该怎么写

Comments

用hook_entity_view_alter()函数的话

wannianchuan's picture

用hook_entity_view_alter()函数的话可以这样写:

mymodule是自定义的模块名称,custom string 是修改后的字符串。
这里是将带链接的edit改成了custom string; delete 的修改同理。

<?php
function mymodule_entity_view_alter(&$build, $type) {
  if (
$type == 'commerce_customer_profile' && $build['commerce_customer_address']['#view_mode'] == 'addressbook') {
   
$build['commerce_addressbook_options']['edit']['#markup'] = 'custom string';
  }
}
?>
waveer's picture

这个只能用在模块中,是吧
如果想在主题中修改,应该怎么修改,因为只为加一个class,加个模块,有点浪费

code is poetry

主题中可以这样写

wannianchuan's picture

<?php
function commerce_kickstart_entity_view_alter(&$build, $type) {
  if (
$type == 'commerce_customer_profile' && $build['commerce_customer_address']['#view_mode'] == 'addressbook') {
   
$build['commerce_addressbook_options']['edit']['#markup'] = l(t('edit'), 'user/' . $build['commerce_customer_address']['#object']->revision_uid . '/addressbook/' . $build['commerce_customer_address']['#object']->type . '/edit/' . $build['commerce_customer_address']['#object']->revision_id);
  }
}
?>

一切正常,谢谢

waveer's picture

一切正常,谢谢

code is poetry

中国 - China

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week