Load Media File in Webform Mail Handler I want to use a single webform to send download links with specific media files to visitors that fill out that form. For example on an URL like this:

https://example.com/downloads?media=1234


The media parameter will be the ID of an media entity type like "Download".  Now I want to send the mail with the name of the media entity and a link to the file of that entity.

How could I get this done? Mail handler and a custom Twig template is what I think about, but how do I get the data of the media entity? Any ideas? Thanks for every helpful comment ;)
$media_id = \Drupal::request()-&gt;get('media'); // get value of media query param

$media = Drupal\media\Entity\Media::load($media_id); // load the Media entity

$media_name = $media-&gt;getName(); // get the media item name

$media_field = $media-&gt;get('field_media_image')-&gt;first()-&gt;getValue(); // get media field

$file_id = $media_field['target_id']; // get the File ID

$file =  Drupal\file\Entity\File::load($file_id); // load File entity

$image_url = $file-&gt;url(); // get image url




You could take this shortcut instead of writing the last 4 lines.

$image_url = $media-&gt;get('field_media_image')-&gt;entity-&gt;url();