How can I get the uploaded file path of a contact form in drupal 8 I'm using the hook_mail_alter() to create a custom email for contact forms.
I was able to get the fields labels and values and use a twig template to send the email. Most of it is working just fine, but my problem is when I use file fields on the contact form. I want to be able to show the path of the uploaded files. When I use the default drupal email, it shows the paths at the end of the file. I want to do the same thing at my custom email. Can anyone tell me how to do this?
You can get the file entity directly from the field and check if the field is not empty before applying any methods on the file object:

/** @var \Drupal\contact\Entity\Message $contactMessage */
$contactMessage = $message['params']['contact_message'];
$file = $contactMessage-&gt;field_file-&gt;entity;
if (!empty($file)) {
  $fileInfo[] = [
    'value' =&gt; $file-&gt;getFilename(),
    'url' =&gt; $file-&gt;url(),
  ];
}