Iterate over items in FieldItemList? 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-&gt;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 &lt; $number_of_photos; $i++) {
      $pic = file_create_url($variables['elements']['photos'][$i]['#file']-&gt;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 }}
PHP calls getIterator() for you, you don't have to do that. Also use $variables['node'], much easier to access.

File/Image references an extension of entity references, which means they inherit the computed ->entity property, which automatically loads the referenced entity. Make sure you check if the file can be loaded, or inconsistent data (if, for some reason, the file gets deleted. Less likely for files but could happen for node or other references) would result in a fatal error.

foreach ($variables['node']-&gt;photos as $item) {
  if ($item-&gt;entity) {
    $uri = $item-&gt;entity-&gt;getFileUri();
  }
}


$uri is something like 'public://your_file.jpg'. You can create a public url with file_create_url() or you can also pass it to an image style entity's buildUrl() method to get the URL for a given image style.

See http://wizzlern.nl/drupal/drupal-8-entity-cheat-sheet for common ways to access field values, what properties exist for each field type and much more.