ideas icon indicating copy to clipboard operation
ideas copied to clipboard

Adding Configuration Field Sections to Existing Fieldtypes

Open joshdaugherty opened this issue 10 months ago • 2 comments

Add a mechanism for adding configuration fields within sections (along with the section display label and instructions) when adding the configuration fields to existing fieldtypes (i.e. https://statamic.dev/extending/fieldtypes#adding-configuration-fields-to-existing-fieldtypes), similar to how you're able to define that for a Section in a Blueprint.

Otherwise, all appended configuration fields are listed together with no ability to separate them or to provide shared instructions.

The basics of appendConfigField from the documentation:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Statamic\Fieldtypes\Text;

class FieldtypeServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Text::appendConfigField('group', [
            'type' => 'text',
            'display' => 'Group',
        ]);
    }
}

Maybe that means new appendConfigFieldSection/appendConfigFieldSections functions or a modification to appendConfigField/appendConfigFields, but the outcome would be to define something like the following:

use Statamic\Fieldtypes\Text;

// One section...
Text::appendConfigFieldSection([
    'display' => 'Section Title',
    'instructions' => 'Instructions for the section',
    'fields' => [
        'foo' => [
            'type' => 'text',
            'display' => 'Foo',
        ],
        'bar' => [
            'type' => 'text',
            'display' => 'Bar',
        ]
    ]
]);

// Multiple sections...
Text::appendConfigFieldSections([
    [
        'display' => 'Section A Title',
        'instructions' => '...',
        'fields' => [...]
    ],
    [
        'display' => 'Section B Title',
        'instructions' => '...',
        'fields' => [...]
    ]
]);

And that would result in the necessary div.publish-section-header, header.publish-section-header, etc. in the control panel for that fieldtype.

Image

joshdaugherty avatar Mar 06 '25 16:03 joshdaugherty