Closed Grafikart closed 4 years ago
Thanks for the suggestion!
I wonder, is it common to add custom configuration to core fields? What is the use case?
I guess we could add a section to the README on writing custom fields which extends the base Field
class.
You are right extending Field
to create a custom FlexibleContent (or any required specific configuration) is a better practice. This idea could solve some use case but could lead to a more bloated code.
I've added a new issue to keep track of the new documentation section: #46
I reopen it since I have discovered new use case that are not in the WordPlate ACF API :
I use class to define fields and I need to retrieve the class name use for rendering
Layout::make($label, $name)
->set('controller_class', 'MyController')
->set('rendering_class', self::class);
I'll do a PR for this
It could fill non existing API like setting menu_order.
Maybe we could add a menuOrder
method. Are there any other non-existing settings hidden in the ACF interface but accessible through code?
It could also be used to pass arbitrary information with the fields
Will this data be saved to the database and is it accessible by the the_field
function=
No, this information is persisted in the configuration that can be accessed using
acf_get_field($field)
It retrieves the config option defined with the field
We've discussed this internally and decided to not add this feature for now. This can be solved by users of this package by extending the default fields. We'll document custom fields (#46) before releasing the next major version. We're very thankful for the pull request and might revisit this in the future if more people request this feature.
Again, thanks for all pull requests you send us Jonathan! Keep up the good work 🙌
A generic option setter
Sometimes, especially with plugins, I need to set some specific key that aren't registered within ACF API. $config is protected and there is no way (or I missed something) to create an arbitrary configuration.
Before doing a PR I want to discuss the idea :
set() proposition
A
set()
method could serve as a bridge to add new config keys.append() proposition
An
append()
method could be used to add multiple keys