function _twig_extract_field_items in Twig Input Filter 7
Extracts field items from a given field renderable.
1 call to _twig_extract_field_items()
- _twig_extract_entity_fields in ./
twig.utils.inc - Extracts entity fields from a given entity renderable.
File
- ./
twig.utils.inc, line 64 - Helper functions for the Twig module.
Code
function _twig_extract_field_items($build) {
$items = array();
if (isset($build['#items']) && is_array($build['#items'])) {
foreach ($build['#items'] as $delta => $item) {
$item = $build[$delta];
if ($build['#field_type'] == 'field_collection') {
$entity_build = reset($item['entity']['field_collection_item']);
$fields = _twig_extract_entity_fields($entity_build);
$wrapper = entity_metadata_wrapper($entity_build['#entity_type'], $entity_build['#entity']);
if (isset($wrapper->twig_template) && ($template = $wrapper->twig_template
->value())) {
$fields['template'] = $template;
}
$items[] = $fields;
}
else {
$items[] = drupal_render($item);
}
}
$field = field_info_field($build['#field_name']);
if ($field['cardinality'] == 1) {
return $items[0];
}
}
return $items;
}