Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
for dispaly key a field
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:
field_list is name of my listbox field
field_image is name of my image field
Use field_info_field()
Try using this :
$key = 0; // Or whatever
$field = field_info_field('field_marital_status');
$label = $field['settings']['allowed_values'][$key];
Works like a charm
Thank you. It works like a charm.
The above works well in some cases
Most cases. No. All cases.
Such a shame I cannot delete this comment.
Bumping into this. It worked
Bumping into this. It worked like a charm to me as well, much appreciated.
Any idea why this approach
Any idea why this approach might have an issue with PHP8?
__________
Eric Aitala - ema13@psu.edu
Penn State
224b8605113373e086cb27708ff301ba18ce394db1996e7e22928e4555e0d20b1b6cecc7f67c9bd9e536cb915779c485