Uh oh!
There was an error while loading. Please reload this page.
Make fieldtype config extendable - #5077
Conversation
jsblair9
commented
Jan 16, 2022
Would love this! |
jasonvarga
commented
Jan 16, 2022
I don't think you'd be able to that in this PR's current state. |
aerni
commented
Jan 18, 2022
Yes, I figured that much. What do you think about the idea though? I think the most obvious use case is regular blueprints vs. form blueprints. The field settings in regular blueprints affect the CP, while field settings in form blueprints affect the frontend. You might have field configuration options that don't make sense for both. Like |
In that case I'd be more inclined to have something like Can you give an example of your original idea? I don't really understand why a user would want to push additional config fields to a fieldtype they don't have control over. |
aerni
commented
Jan 20, 2022
The idea is to make it possible for addon developers to add their own fields if needed. I've got two addons that would benefit from this right now: Factory and Livewire Forms. Both addons hook into the config of blueprint fields. The Livewire Forms addon for instance does some stuff depending on a |
jasonvarga
commented
Jan 20, 2022
Ok cool I gotcha. That's fine! I'd say let's leave the "only render on form blueprint" thing to a separate feature. But for your Factory/Livewire example, I think this works nicely. |
jasonvarga
left a comment
There was a problem hiding this comment.
Calling AnyFieldtype::extendConfigFields() will add those fields to all fieldtypes. It should only go into the one you intended.
Also, can we change it to extendConfigField() (singular) and pass in a single field that gets pushed onto an array. It's possible multiple developer would be using this and in its current state they'd just stomp over the first.
Finally, if possible please add a test for this into FieldtypeTest.php
Thanks!
aerni
commented
Jan 27, 2022
Good call! The fields are now only added to the intended fieldtype. I settled on Every time you call There's also a new method I also added tests as requested. |
jasonvarga
commented
Jan 27, 2022
Thank you! |
ryanmitchell
commented
Jan 29, 2022
@aerni do you think you could do a PR on the docs to explain this a bit? |
This PR lets you extend the default config fields of a fieldtype as requested in statamic/ideas#206. This can be useful for extra fields used by addons.
One thing that might be handy is the ability to only add certain fields depending on context. For instance, a
autocompleteconfig field would be useful for the Text fieldtype. But only in form blueprints.