function field_view_value

Returns a renderable array for a single field value.

Parameters

$entity_type: The type of $entity; e.g., 'node' or 'user'.

$entity: The entity containing the field to display. Must at least contain the id key and the field data to display.

$field_name: The name of the field to display.

$item: The field value to display, as found in $entity->field_name[$langcode][$delta].

$display: Can be either the name of a view mode, or an array of display settings. See field_view_field() for more information.

$langcode: (Optional) The language of the value in $item. If not provided, the current language will be assumed.

Return value

A renderable array for the field value.

Related topics

1 call to field_view_value()
FieldDisplayAPITestCase::testFieldViewValue in modules/field/tests/field.test
Test the field_view_value() function.

File

modules/field/field.module, line 796

Code

function field_view_value($entity_type, $entity, $field_name, $item, $display = array(), $langcode = NULL) {
    $output = array();
    if ($field = field_info_field($field_name)) {
        // Determine the langcode that will be used by language fallback.
        $langcode = field_language($entity_type, $entity, $field_name, $langcode);
        // Push the item as the single value for the field, and defer to
        // field_view_field() to build the render array for the whole field.
        $clone = clone $entity;
        $clone->{$field_name}[$langcode] = array(
            $item,
        );
        $elements = field_view_field($entity_type, $clone, $field_name, $display, $langcode);
        // Extract the part of the render array we need.
        $output = isset($elements[0]) ? $elements[0] : array();
        if (isset($elements['#access'])) {
            $output['#access'] = $elements['#access'];
        }
    }
    return $output;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.