How to make a custom field that takes either a URL or a file?

Did anyone try to do this before?
I am trying to have a field for a Video that can either be from YouTube, Vimeo or a file.

That’s possible in theory with template code like that:

<?php if($file = $page->video()->toFile()): ?>
  ...output file...
<?php else: ?>
  probably a URL
<?php endif ?>

The disadvantage is that automagic detection like that can be hard to debug, especially for clients (“why doesn’t it use the file, oh, typo”).
So I’d recommend using a radio field together with the text input field so that the user can select whether the video is a file, YouTube or Vimeo.

I prefer using two fields and adding a help text below like: „If you are using a local video file the YouTube/Vimeo video won’t be desplayed“. Or as mentioned by @lukasbestle an additional radio field.

It’s much easier to maintain and you can use optimized input types for both fields (e.g. select field for local files with dynamic video option). Less errors and better UI/UX :wink: