Skip to content

[6.x] Add extra sections with fields to existing fieldtypes - #13796

Merged
jasonvarga merged 8 commits into
statamic:6.xfrom
nopticon:feature/make-fieldtype-accept-sections
Sep 1, 2026
Merged

[6.x] Add extra sections with fields to existing fieldtypes#13796
jasonvarga merged 8 commits into
statamic:6.xfrom
nopticon:feature/make-fieldtype-accept-sections

Conversation

@nopticon

@nopticon nopticon commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

After reading https://statamic.dev/fieldtypes/build-a-fieldtype#adding-config-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

@nopticon
nopticon marked this pull request as draft February 2, 2026 18:31
@nopticon
nopticon marked this pull request as ready for review February 2, 2026 18:31
@nopticon nopticon changed the title [6.x] Add config extra sections with fields to existing fieldtypes Feb 2, 2026
@nopticon
nopticon marked this pull request as draft February 2, 2026 18:41
@ryanmitchell

Copy link
Copy Markdown
Contributor

Related: #12723

@duncanmcclean duncanmcclean linked an issue Feb 2, 2026 that may be closed by this pull request
@nopticon
nopticon marked this pull request as ready for review February 3, 2026 05:38
Comment thread src/Fields/Fieldtype.php Outdated

private function extraConfigFieldsUseSections($extras)
{
return collect($extras)->filter(fn ($field) => Arr::has($field, 'fields'));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is the right way to check, as replicators and bards both have fields so this check would mark them both as sections.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ryanmitchell Are you referring to replicators and bard fields that you want to add with appendConfigFields method? Something like this:

image

This check does validate fields key on the first level of the array generated by

protected function extraConfigFieldItems(): array
but it's not recursive for other fields keys, so I haven't seen the behavior that you mentioned. This PR does not affect other existing fields beside the ones that you define calling appendConfigField or appendConfigFields method.

I did a lot of tests in my dev site and all fields seems to be working fine, if you see something weird is happening please let me know. Thanks for your review!

This is how it looks for my custom test calling Text::appendConfigFields():

image
jackmcdade and others added 2 commits August 18, 2026 20:00
The fields-key heuristic treated Grid/Group extras as sections, and extra sections never actually became sections on linear fieldtypes. Drop the unrelated isRequired guard.

Co-authored-by: Cursor <cursoragent@cursor.com>
@jasonvarga
jasonvarga merged commit 93187ad into statamic:6.x Sep 1, 2026
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment