Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Extra values for field conditions. Add extra asset values. #10588

Merged
merged 5 commits into from
Oct 21, 2024

Conversation

daun
Copy link
Contributor

@daun daun commented Aug 7, 2024

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 to mime_type to match the yaml key?

@daun daun changed the title [5.x] Conditional fields in asset blueprints [5.x] Make native asset data available in field conditions Oct 13, 2024
@jasonvarga jasonvarga changed the title [5.x] Make native asset data available in field conditions [5.x] Extra values for field conditions. Add extra asset values. Oct 21, 2024
Copy link
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this.

We weren't in love with having to hack hidden fields in there, but I understand why you did it.

We introduced the concept of "extra" values that can be used by the field condition validator, and put the extra asset data into there. I could see in the future this being useful in other places like entries etc.

@daun
Copy link
Contributor Author

daun commented Oct 21, 2024

@jasonvarga Right, the hidden fields didn't feel great, it looks much better with the extra values concept.

@jasonvarga jasonvarga merged commit cce7045 into statamic:5.x Oct 21, 2024
17 checks passed
@daun daun deleted the feature/asset-editor-with-meta branch October 25, 2024 08:26
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.

Allow access to underlying asset data in asset blueprint fields
2 participants