In other words: How do I get the URI for each of the files in a file field that's on a custom content entity called 'listing'.
Right now I have:
$images = $variables['elements']['photos']['#items'];
Where $images is a FieldItemList
How do I iterate over my FieldItemList to grab the URI for each of the files referenced therein?
Ok figured first part out with:
$images = $variables['elements']['photos']['#items'];
$photos = $images->getIterator();
foreach ($photos as $photo) {
xdebug_break();
}
Now the question is:
How to get the URI for each of $photo, and assign it as a variable...?
Update
After Berdir's Comment and my own investigation this is what I went with.
if (isset($variables['elements']['photos']['0'])) {
$number_of_photos = count($variables['elements']['photos']['#items']);
$listing_pics = [];
for ($i = 0; $i < $number_of_photos; $i++) {
$pic = file_create_url($variables['elements']['photos'][$i]['#file']->getFileUri());
$listing_pics[] = $pic;
}
$variables['elements']['listing_photos'] = $listing_pics;
}
This is in a Hook_template_preprocess_HOOK(), and now all of the urls from my multi-value file field are available to the template like this {{ elements.listing_photos }}