cms
cms copied to clipboard
[5.x] Add config extra sections with fields to existing fieldtypes
After reading https://statamic.dev/extending/fieldtypes#adding-configuration-fields-to-existing-fieldtypes I noticed that extra sections are not added to fieldtype config.
use Statamic\Fieldtypes\Text;
Text::appendConfigFields([
[
'display' => __('Extra section'),
'fields' => [
'more_options' => [
'display' => __('Options'),
'instructions' => __('Instructions for this field'),
'type' => 'array',
],
],
],
]);
Before this fix, it shows like this:
After fixing this issue, it shows fields inside the new section:
After adding appendConfigFields to a ServiceProvider, it can be tested on any blueprint at /cp/collections/{collection}/blueprints/{blueprint}/edit
This PR adds extra sections support to #5077 and #7706
I don't love the idea of adding a new method just so you can specify a section. 🤔
I wonder if we could add a $section argument to the existing extendConfigFields method, kinda like we have in the Blueprint class, allowing you to specify a tab when ensuring a field:
https://github.com/statamic/cms/blob/7be04816733ba3e7b5efd3a661972ace784af972/src/Fields/Blueprint.php#L535
Hi Duncan! This PR does not add a new method, just enhances how the existing "appendConfigFields" method handles the array when it contains the "fields" key. Please let me know if any questions.
Sorry, ignore me! 🙈
I was reading https://github.com/statamic/cms/pull/5077 and saw extendConfigFields but didn't realise the method name got changed to appendConfigFields before it was merged.
Ok will do!