1 field.module field_get_values(Entity $entity, $field_name, $value_key = 'value', $langcode = NULL)

Returns all values 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

(array): All field values, or an empty array 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

field_get_value()

Related topics

File

core/modules/field/field.module, line 727
Attach custom data fields to Backdrop entities.

Code

function field_get_values(Entity $entity, $field_name, $value_key = 'value', $langcode = NULL) {
  return $entity->getFieldValues($field_name, $value_key, $langcode);
}