cms
cms copied to clipboard
[5.x] Make native asset data available in field conditions
Make native asset data (width, height, filename, etc) available as hidden fields inside the asset editor component.
This enables field conditions inside asset blueprints against native asset data, e.g. to show fields for some filetypes only.
Closes statamic/ideas#1136
Example use case
The example below will show an Autoplay toggle for all videos shorter than a minute:
fields:
-
handle: autoplay
field:
type: toggle
display: Autoplay
if:
extension: mp4
duration: '<= 60'
Required changes
- Asset Resource class: Append mimetype and duration in Asset resource
- Asset Editor component: Create hidden fields for asset data, merge asset data with blueprint field data
Notes
- Hiding the fields in the blueprint also ensures their data isn't sent along when saving the asset
- The mime type field is available as
mimeType— should this be snake-cased tomime_typeto match the yaml key?