1 field.module | field_get_value(Entity $entity, $field_name, $value_key = 'value', $langcode = NULL) |
Returns the first value from a field.
@since 1.13.0 Function added.
Parameters
Entity $entity: The fully-loaded entity containing the field value requested.
string $field_name: The machine name of the field.
string $value_key: The key indicating the primary data value for the field. Defaults to 'value' which is used in both text and number fields. For fields which do not have a 'value' key such as terms (which use a 'tid' key) or files (which use a 'fid' key), the key must be specified.
string $langcode (optional): The language code for the requested language. Defaults to the current language.
Return value
The first field value, or NULL if the field is empty, if the field does not: contain the $value_key specified, or if the entity does not contain the $field_name specified.
See also
Related topics
File
- core/
modules/ field/ field.module, line 729 - Attach custom data fields to Backdrop entities.
Code
function field_get_value(Entity $entity, $field_name, $value_key = 'value', $langcode = NULL) {
return $entity->getFieldValue($field_name, $value_key, $langcode);
}