如何在Drupal中以编程方式创建自定义显示套件字段

时间:2015-08-29 11:14:43

标签: drupal

我想将我的代码从Drupal的界面移到我的自定义显示套件字段中,并将它们放入自定义模块中。我启用了我的自定义模块和刷新的缓存,我找不到我在节点字段的管理显示选项卡中创建的字段或我的分类术语字段:

function my_module_entity_property_info_alter(&$info) {
  $info['taxonomy_term']['properties']['district_address'] = array(
    'label' => t('District address'),
    'type' => 'text',
    'getter callback' => 'district_address_callback',
    'entity views field' => TRUE
  );
  $info['node']['properties']['biography'] = array(
    'label' => t('Biography'),
    'type' => 'text',
    'getter callback' => 'biography_callback',
    'entity views field' => TRUE
  );
}

/**
 * Custom district address getter callback
 */
function district_address_callback($entity) {
  $street = $entity->field_address['und'][0]['street'];
  $output = '<div class="container">' . $street . '</div>';
  return $output;
}

/**
 * Custom biography getter callback
 */
function biography_callback($entity) {
  dpm($entity);
  $output = '<div class="container"><p>Biography goes here ...</p></div>';
  return $output;
}

0 个答案:

没有答案