我有一个“医疗记录”内容类型,其中嵌入了一个“医疗过程”字段(type=paragraphs包,数值无限)。在段落中,its有访问时间、诊断、治疗、图像等,因此段落可以记录每一次访问。
但是,如果我们有很多段落,在视图页面中,它看起来很难看,所以我想在每个访问记录在这里输入图像描述(段落)中添加一些标签,例如“第一次访问”、“第二次访问”、“访问%...as”--我知道字段组只能显示一个静态标签,标记是不可用的。有人知道如何实现这一点吗?

发布于 2018-08-13 12:22:13
可以在呈现之前使用hook_node_view更改视图。
/**
*
* @param type $node
* @param type $view_mode
* @param type $langcode
* Implements hook_node_view().
* To change paragraph title in node view.
*/
function MYMODULE_node_view($node, $view_mode = 'full', $langcode = NULL) {
if ($node->type == 'CONTENT-TYPE-ID' && $view_mode == 'full') {
foreach ($node->content['field_medical_records'] as $key => $paragraph_values) {
if (is_numeric($key)) {
$item_key = key($paragraph_values['entity']['paragraphs_item']);
$node->content['field_medical_records'][$key]['entity']['paragraphs_item'][$item_key]['field_visit_time']['#title'] = numToOrdinalWord($item_key) . ' Visit';
}
}
}
}
/**
*
* @param type $num
* @return string
* Implement to get Ordinal word from number.
*/
function numToOrdinalWord($num) {
$first_word = array('eth', 'First', 'Second', 'Third', 'Fouth', 'Fifth', 'Sixth', 'Seventh', 'Eighth', 'Ninth', 'Tenth', 'Elevents', 'Twelfth', 'Thirteenth', 'Fourteenth', 'Fifteenth', 'Sixteenth', 'Seventeenth', 'Eighteenth', 'Nineteenth', 'Twentieth');
$second_word = array('', '', 'Twenty', 'Thirty', 'Forty', 'Fifty');
if ($num <= 20) {
return $first_word[$num];
}
$first_num = substr($num, -1, 1);
$second_num = substr($num, -2, 1);
return $string = str_replace('y-eth', 'ieth', $second_word[$second_num] . '-' . $first_word[$first_num]);
}您可以根据需要更改字段名。
https://drupal.stackexchange.com/questions/267454
复制相似问题