Created
June 14, 2018 12:12
-
-
Save modcab/f84add9a74366aa244461889b50118aa to your computer and use it in GitHub Desktop.
Drupal 8 - Extract file url from media field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = $item['content']['field_media_image'][0]['#url']; | |
$media_id = $url->getRouteParameters()['media']; | |
$media = entity_load('media', $media_id); | |
$filefield = $media->field_image_file->referencedEntities(); | |
$entity = current($entity); | |
$uri = $entity->getFileUri(); | |
$url = Url::fromUri(file_create_url($uri))->toString(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment