使用theme_preprocess_field()更改字段

时间:2013-03-29 07:00:04

标签: drupal drupal-7

gunwinner是我的主题名称,我想更改特定内容类型的字段。 我试过这段代码,

function gunwinner_preprocess_field(&$variables) {
  $element = $variables['element'];
  if($element['#field_name'] == 'field_deal_url') {
     $values = $element['#items'][0]['value'];
     $deal_link = l(t("Go to Store"), "$values", array('attributes' => array('class' => 'store-link')));
     $element['#items'][0]['value'] = "Store";
  return;
  }
}

返回带有链接标题“Go to Store”的数组,但它没有反映在特定字段的页面上。

任何人都可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

您正在制作$variables['element']的副本并对其进行操作,因此更改不会保留在原始变量中。

只需将功能的第一行更改为

即可
$element = &$variables['element'];