我在这里遵循了一个很好的教程:http: //previousnext.com.au/blog/creating-custom-display-suite-fields-or-how-i-learned-stop-worrying-and-use-hookdsfieldsinfo以编程方式创建海关带有 hook_ds_fields_info() 的字段。
在下面的代码中,我尝试使用 text_trimmed 格式化程序,但在 UI 中我没有得到修剪格式的设置。
/**
* Implements hook_ds_fields_info().
*/
function my_module_ds_fields_info($entity_type) {
$fields = array();
$fields['node']['article_footnote'] = array(
'title' => t('Article footnote'),
'field_type' => DS_FIELD_TYPE_FUNCTION,
'function' => 'my_module_ds_field_article_footnote',
'ui_limit' => array('my_content_type|*', '*|search_index'),
'properties' => array(
'formatters' => array(
'text_default' => t('Default'),
'text_plain' => t('Plain text'),
'text_trimmed' => t('Trimmed'),
),
),
);
if (isset($fields[$entity_type])) {
return array($entity_type => $fields[$entity_type]);
}
return;
}
/**
* Render the article footnote field.
*/
function my_module_ds_field_article_footnote($field) {
$content = 'All articles are composed in a permanent state of coffee frenzy.';
return $content;
}