You are here

public function FieldValueExtension::getFieldValue in Twig Field Value 8

Same name and namespace in other branches
  1. 2.0.x src/Twig/Extension/FieldValueExtension.php \Drupal\twig_field_value\Twig\Extension\FieldValueExtension::getFieldValue()

Twig filter callback: Only return a field's value(s).

Parameters

array|null $build: Render array of a field.

Return value

array Array of render array(s) of field value(s). If $build is not the render array of a field, NULL is returned.

File

src/Twig/Extension/FieldValueExtension.php, line 61

Class

FieldValueExtension
Provides field value filters for Twig templates.

Namespace

Drupal\twig_field_value\Twig\Extension

Code

public function getFieldValue($build) {
  if (!$this
    ->isFieldRenderArray($build)) {
    return NULL;
  }
  $elements = Element::children($build);
  if (empty($elements)) {
    return NULL;
  }
  $items = [];
  foreach ($elements as $delta) {
    $items[$delta] = $build[$delta];
  }
  return $items;
}