function field_get_items

8.x field.module field_get_items(EntityInterface $entity, $field_name, $langcode = NULL)

Returns the field items in the language they currently would be displayed.

Parameters

\Drupal\Core\Entity\EntityInterface $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 with available field items keyed by delta.

Related topics

2 calls to field_get_items()
file_get_file_references in drupal/core/modules/file/file.module
Retrieves a list of references to a file.
node_tokens in drupal/core/modules/node/node.tokens.inc
Implements hook_tokens().

File

drupal/core/modules/field/field.module, line 880
Attach custom data fields to Drupal entities.

Code

function field_get_items(EntityInterface $entity, $field_name, $langcode = NULL) {
  $entity = $entity->getBCEntity();
  $langcode = field_language($entity, $field_name, $langcode);
  return isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : array();
}