0

I can't manage to get the video link of a media, I can achieve this with a picture but with videos it doesn't work.

This is the code I am using.

function slider_get_uri_by_media($media, $style = 'background'){
  // kint(isset($media->file_media_video_file));
  if (isset($media->field_media_image)){
    $file = $media->field_media_image->entity;
    if ($file && $fid = $file->id()) {
      $image = File::load($fid);
      if ($image_style = ImageStyle::load($style)) {
        return ['url' => file_url_transform_relative($image_style->buildUrl($image->getFileUri()))];
      }
    }
  }
  elseif (isset($media->file_media_video_file)) {
    $file = $media->file_media_video_file->entity;
    if ($file && $fid = $file->id()) {
      $video = File::load($fid);
    }
  }
}

Why cannot I get the path for the video stored in $media->field_media_video_file?

closed as off-topic by kiamlaluno Apr 22 at 15:15

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question was caused by a problem that can no longer be reproduced, was solved by a cache clear, or was a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers." – kiamlaluno
If this question can be reworded to fit the rules in the help center, please edit the question.

1

I think that you have a typo in the field name, you should replace $media->file_media_video_file with $media->field_media_video_file (2 times)