Skip to content

Adding Configuration Field Sections to Existing Fieldtypes #1317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
joshdaugherty opened this issue Mar 6, 2025 · 2 comments
Open

Adding Configuration Field Sections to Existing Fieldtypes #1317

joshdaugherty opened this issue Mar 6, 2025 · 2 comments

Comments

@joshdaugherty
Copy link

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

@duncanmcclean
Copy link
Member

duncanmcclean commented Mar 6, 2025

What's your use case for needing to add options to core fieldtypes?

@joshdaugherty
Copy link
Author

The particular use case at the moment was input mask configuration, a la IMask (https://imask.js.org/). The fields would be the input mask pattern, forcing uppercase/lowercase, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants