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

Aggregate Fieldtype #638

Closed
aerni opened this issue Sep 3, 2021 · 6 comments
Closed

Aggregate Fieldtype #638

aerni opened this issue Sep 3, 2021 · 6 comments

Comments

@aerni
Copy link

aerni commented Sep 3, 2021

I'm building a fieldtype that acts as a wrapper for multiple fields. One of the reasons is to save the data in a separate array.

I want this:

seo:
  title: 'A title'
  description: 'Description'

… not this:

title: 'A title'
description: 'Description'

My fieldtype looks the same as the SeoProFieldtype and ResponsiveFieldtype.

The problem with this approach is that the syncable property on the publish-field component doesn't work as expected. It just works for the wrapper fieldtype itself but not for the fields within. I could imagine that there are other issues with this approach as well.

My proposal is a new aggregate fieldtype that can wrap multiple fields. This might be connected to the UI Fieldtype idea.

@aerni
Copy link
Author

aerni commented Sep 3, 2021

I just realized that this could probably also be done with fieldsets. Fieldsets already serve as a wrapper for multiple fields. You could add an option to save the data of the imported fieldset in its own key. Similar to the prefix option.

The only drawback with this approach is that you lose the capabilities of a true fieldtype with its PHP file.

@aerni
Copy link
Author

aerni commented Sep 7, 2021

I dug a little deeper. If you wanted the sync feature to work on each field, we'd need to make sure, that each field is pushed to the localizedFields array in the store. Probably also need to change some other things.

https://github.com/statamic/cms/blob/6d1ebe950ca397e98b0a20ef4c9a6dfd6b21ec25/resources/js/components/publish/Field.vue#L182-L184

The same "only top-level fields can be localized" issue goes for Bard, Replicator, and Grid fieldtype. Might be connected to this: #439

@aerni
Copy link
Author

aerni commented Sep 7, 2021

Similar if not the same idea: #210

@jasonvarga
Copy link
Member

The top level fields issue is a complicated one.

We don't have a good way to know if you want to override just a nested key(s) or the whole thing.

@aerni
Copy link
Author

aerni commented Sep 8, 2021

Yeah, I figured. Another beefy idea on your table. Fun.

@duncanmcclean
Copy link
Member

Just came across this issue... it's now possible using the Group fieldtype.

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

No branches or pull requests

3 participants