| 7 field.module | field_get_items($entity_type, $entity, $field_name, $langcode = NULL) |
| 8 field.module | field_get_items($entity_type, $entity, $field_name, $langcode = NULL) |
Returns the field items in the language they currently would be displayed.
Parameters
$entity_type: The type of $entity; e.g., 'node' or 'user'.
$entity: The entity containing the data to be displayed.
$field_name: The field to be displayed.
$langcode: (optional) The language code $entity->{$field_name} has to be displayed in. Defaults to the current language.
Return value
An array of field items keyed by delta if available, FALSE otherwise.
Related topics
3 functions call field_get_items()
File
- modules/
field/ field.module, line 970 - Attach custom data fields to Drupal entities.
Code
<?php
function field_get_items($entity_type, $entity, $field_name, $langcode = NULL) {
$langcode = field_language($entity_type, $entity, $field_name, $langcode);
return isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : FALSE;
}
?> Login or register to post comments
Comments
Related API Function field_view_value()
It is worth noting that field_get_items() returns raw values the use of which can be a security risk. Passing the raw values through field_view_value() handles the sanitizing of the values.
Context
field_get_items() without an explicit
langcodeparameter should be used only in a display/render context since it will return the field items corresponding to the current display language.