cms icon indicating copy to clipboard operation
cms copied to clipboard

[5.x] Add config extra sections with fields to existing fieldtypes

Open nopticon opened this issue 7 months ago • 4 comments

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:

image

After fixing this issue, it shows fields inside the new section:

image

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

nopticon avatar Apr 16 '25 20:04 nopticon

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

duncanmcclean avatar May 23 '25 09:05 duncanmcclean

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.

nopticon avatar May 23 '25 14:05 nopticon

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.

duncanmcclean avatar May 23 '25 14:05 duncanmcclean

Ok will do!

nopticon avatar May 23 '25 14:05 nopticon