Skip to content

[6.x] Augment video fields to a value object carrying the provider - #15458

Open
edalzell wants to merge 1 commit into
statamic:6.xfrom
edalzell:feature/video-value-object
Open

edalzell wants to merge 1 commit into
statamic:6.xfrom
edalzell:feature/video-value-object

Conversation

@edalzell

Copy link
Copy Markdown
Contributor

The video fieldtype doesn't implement augment(), so the raw string is all a template ever gets. There's no provider discriminator, and no first-class way to get an embed URL — {{ video_field | embed_url }} works only because CoreModifiers::embedUrl() happens to know how to rewrite YouTube and Vimeo URLs by hand.

This augments to a Statamic\Fieldtypes\Video\Video value object exposing provider, id, url and embed_url, following the ArrayableString/ArrayableLink convention: __toString() returns the original value, so {{ video_field }} is unchanged, and it implements Arrayable, ArrayAccess, Boolable and JsonSerializable. It recognises YouTube, Vimeo, direct video files (via FileTypes::video()) and cloudflare:<id> values, falling back to an unsupported provider.

The YouTube/Vimeo URL→embed logic is moved out of CoreModifiers::embedUrl() onto the value object, and the modifier now delegates to it — one implementation rather than two. embedUrl, trackableEmbedUrl and isEmbeddable also accept the object directly. The existing modifier tests pass unchanged, which is the regression proof for the move.

Worth a look: augment() returns the object for all values, including plain URLs. __toString() covers direct output, modifiers and GraphQL (the existing GraphQL test still passes unchanged), but a strict is_string() check downstream would now see an object. Happy to keep plain URLs as strings and only return the object for cloudflare: values if you'd rather not change that surface in a major.

Split out of #11871 so the augmentation contract can be settled on its own, ahead of the Cloudflare Stream and oEmbed work. No new dependencies.

@edalzell
edalzell force-pushed the feature/video-value-object branch from 62b7e0b to ca149d0 Compare September 14, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant