You can use hook_node_view to change the view before rendering.
/**
*
* @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]);
}
You can change field names as per your requirement.