I am trying to alter field values in a page display. I can get the field values easily using field_get_items(), but depending on the values of other fields, I may need to manipulate the text and/or display based on some PHP logic in my template file. I am trying to do it using either hook_page_alter() or hook_preprocess_HOOK().
I cannot get the text to be altered when the page is displayed using hook_page_alter()
or hook_preprocess_HOOK()
. I can confirm those 2 functions are working and that I can pull the values from the DB ($page['content']
), but I cannot override the variable to set them. For example:
function standard_submission_page_alter(&$page) {
$node = menu_get_object();
$page['content']['system_main']['nodes'][$node->nid]['field_title_nickname']['#items'][0]['value'] = 'A new nickname title!';
}
function standard_submission_preprocess_page(&$vars) {
$vars['node']->field_title_nickname['und'][0]['value'] = 'A new nickname title 2x';
}
Any ideas on why my altering of this field_title_nickname
text field value isn't being accepted and displayed? It keeps reverting back to whatever is originally in the database.