diogo Posted 4 hours ago Posted 4 hours ago Hi everyone, I'd like to share MediaFiles, a small module we developed at Konkat, that lets ProcessWire image fields hold videos, next to images and in any order. The pain it scratches Project galleries often mix photos and short videos. Usually that means an image field plus a separate file field for the videos (losing the order between them), a repeater per item, or embeds from YouTube or Vimeo when the client just wants to drop in an mp4. With MediaFiles, editors drag videos into the image field like any other file, even a bunch of images and videos at once, and sort them as they like. Each video gets a poster from its first frame, and editors can pick another frame from the player in the edit panel. Sorting, descriptions, repeaters and Repeater Matrix keep working, because it's still the same image field. It's unobtrusive There's no new field type: add mp4 to an image field's valid extensions, and that's it. In your template, it's just: <?php if($img->filedata('video')): ?> <video controls playsinline poster="<?= $img->url ?>" src="<?= $img->pagefiles->url . rawurlencode($img->filedata('video')) ?>"></video> <?php else: ?> <img src="<?= $img->url ?>" alt="<?= $sanitizer->entities($img->description) ?>"> <?php endif; You might wonder why it's $img->filedata('video') and not something like $img->video. That's on purpose: filedata() is plain core ProcessWire (and so is $img->pagefiles->url), so your templates don't depend on the module at all. The module only acts on fields that allow a video extension, and adds only what videos need. Everything else is core's image field. If you uninstall it, nothing breaks: the website keeps showing the videos, and the admin is a plain image field again. ---- For now, you can find it on GitHub: https://github.com/konkat-studio/MediaFiles I'll add the link to the modules directory as soon as it's available. Feedback is very welcome! 3 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now