1

I have some code to get video using view builder.

$view_builder = \Drupal::entityTypeManager()->getViewBuilder('media');
$storage = \Drupal::entityTypeManager()->getStorage('media');
$entity_id = $storage->load($course_video_source[0]['target_id']);
$build_video_course = $view_builder->view($entity_id, 'default');
$video_html = render($build_video_course);

The $video_html is returned html string as an object. How do I get the source file only without the <video> tag?

object(Drupal\Core\Render\Markup)#21215 (1) {
  ["string":protected]=>
  string(426) "<div><div><div class="visually-hidden">Video file</div><div><div class="video--wrapper"><video-js class="video-js video-container" playsinline="true" crossorigin="anonymous"><source  src="/milo/docroot/sites/default/files/2021-05/1.%20LARI%20-%20SEJARAH%20%28UPDATE%20TERBARU%2016%20Mei%29%20-%203.mp4" type="video/mp4" /></video-js></div></div></div></div>"
}

1 Answer 1

2

Starting with a Media entity:

$media_type = \Drupal::entityTypeManager()->getStorage('media_type')->load($media->bundle());

$file_field_name = $media_type->getSource()->getSourceFieldDefinition($media_type)->getName();

$file_uri = $media->get($file_field_name)->entity->getFileUri();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.