Last updated 21 July 2014. Created on 21 July 2014.
Edited by apmsoonerLog in to edit this page.

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);

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

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);
	}

}


来自  https://www.drupal.org/node/2307109