Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
API page: https://api.drupal.org/api/drupal/core%21modules%21file%21src%21Plugin%2...
Enter a descriptive title (above) relating to class FileItem, then describe the problem you have found:
Hi,
I'm trying to get a file object from a fileItem object.
I succeeded using $fileItem->view()["#file"];
But this is not very obvious.
Better provide a ->getFile() method.
Comments
Comment #2
jp.stacey CreditAttribution: jp.stacey at Magnetic Phield commentedI think this is a feature request (add a new method to FileItem) rather than a documentation request, so I'm going to move it to the file.module.
Likely what they're after could be provided by e.g. entity magic properties (
$fileItem->file
?) but someone else might know better than me.Comment #10
chrisfromredfinYou can do this using
->entity
which is a nice consistent way to do it across all entity references, so this is not needed.