I couldn't figure out how to get the actual label to print instead of the key value. Here is what did the trick for me....

Here's a sample assuming field name is: field_marital_status

The list available values are:
1|Married
2|Single

$status = $entity->field_marital_status[LANGUAGE_NONE][0]['value'];
$status_display = field_view_value($entity_type, $entity, 'field_marital_status', $status, array());


$entity_field[0]['value'] = 'You are' . render($status_display);

Comments

namjoo’s picture

for dispaly key a field

print render($node->field_list['und'][0]['value']);

also can in manage display change default to key for field

for show image and value of a list or check box use:

print render($content['field_list']);
print render($content['field_image']);

field_list is name of my listbox field
field_image is name of my image field

karuna patel’s picture

Try using this :

$key = 0; // Or whatever
$field = field_info_field('field_marital_status');
$label = $field['settings']['allowed_values'][$key];

sri_techie’s picture

Thank you. It works like a charm.

$jid = $row->job_id_181;
if($jid)
{
	$jobNode = node_load($params['jid']);
	$key = $jobNode->field_job_location['und'][0]['value'];//2
	if($key)
	{
		
		$field = field_info_field('field_job_location');
		$label = $field['settings']['allowed_values'][$key];
		dsm($label);
	}

}
MauMau’s picture

Most cases. No. All cases.
Such a shame I cannot delete this comment.

danrod’s picture

Bumping into this. It worked like a charm to me as well, much appreciated.

aitala’s picture

Any idea why this approach might have an issue with PHP8?

__________
Eric Aitala - ema13@psu.edu
Penn State

224b8605113373e086cb27708ff301ba18ce394db1996e7e22928e4555e0d20b1b6cecc7f67c9bd9e536cb915779c485