In Drupal:
$target_id = $variables['content']['field_media']['#items']->getValue()[0]['target_id'];
// Get the entity type manager.
$entity_type_manager = \Drupal::service('entity_type.manager');
// Load the media entity by ID.
$media_entity = $entity_type_manager->getStorage('media')->load($target_id);
// Check if the field exists on the media entity.
if ($media_entity->hasField('field_media_document')) {
// Get the value of the field.
$document_field = $media_entity->get('field_media_document')->getValue();
// Get the file url.
$url = $media_entity->get('field_media_document')->entity->createFileUrl();
$variables['field_media_document_url'] = $url;
}