Skip to content

feat: extensible section form schema via extendSchemaUsing [3.x]#165

Merged
ManukMinasyan merged 1 commit into
3.xfrom
feat/section-form-extend-schema
Jun 14, 2026
Merged

feat: extensible section form schema via extendSchemaUsing [3.x]#165
ManukMinasyan merged 1 commit into
3.xfrom
feat/section-form-extend-schema

Conversation

@ManukMinasyan

Copy link
Copy Markdown
Collaborator

What

Adds an extension point to the Custom Fields section management form.

  • SectionForm::extendSchemaUsing(Closure $callback) — register a callback (e.g. from a service provider) that appends to / modifies the section form schema. A single registration covers both the Add and Edit section modals. The callback receives (array $schema, string $entityType), so extensions can be scoped per entity.
  • SectionForm::flushSchemaExtensions() — clears registrations (test isolation).
  • CustomFieldSectionSettingsData gains a free-form array $extra bag, so arbitrary consumer-defined settings bound under settings.extra.* round-trip through the typed DTO (and through CustomFieldSectionData import/export). The typed DTO silently drops unknown keys, so a bag is required for arbitrary flags to survive hydration.

Why

Applications consuming CustomFields::infolist() need to attach their own per-section metadata — e.g. "render this section as its own tab" — without subclassing the form or patching the vendor.

Usage

// AppServiceProvider::boot()
use Relaticle\CustomFields\Filament\Management\Schemas\SectionForm;
use Filament\Forms\Components\Toggle;

SectionForm::extendSchemaUsing(fn (array $schema, string $entityType): array => [
    ...$schema,
    Toggle::make('settings.extra.render_as_tab')
        ->label('Render as own tab')
        ->visible($entityType === 'contact'),
]);

// read it back
$renderAsTab = $section->settings->extra['render_as_tab'] ?? false;

Test plan

New tests in CustomFieldsSectionManagementTest:

  • extension callback receives the section entity type
  • a field added via extendSchemaUsing persists into settings.extra on create
  • the extra value survives an edit round-trip

Verified locally: full suite 694 passed; Pint, PHPStan, Rector --dry-run, and arch tests all green. (Type coverage sits at 99.4% on 3.x already — pre-existing, in unrelated files.)

Notes

  • Additive and backward-compatible: the new DTO property defaults to []; the hook is opt-in.
  • No migration — settings is already JSON.

Add SectionForm::extendSchemaUsing() so applications can append fields to the section management form from a service provider, without subclassing or vendor patching. One registration covers both the Add and Edit section modals; the callback receives the current schema and the section entity type. flushSchemaExtensions() resets registrations (used in tests).

Give CustomFieldSectionSettingsData a free-form extra array so consumer flags bound under settings.extra.* round-trip through the typed DTO (and through CustomFieldSectionData import/export). Enables flagging a section to render as its own tab.
@ManukMinasyan ManukMinasyan merged commit 07eca80 into 3.x Jun 14, 2026
4 checks passed
@ManukMinasyan ManukMinasyan deleted the feat/section-form-extend-schema branch June 14, 2026 10:47
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

Successfully merging this pull request may close these issues.

1 participant