Skip to content

feat: customize the brick form's action per field with brickAction() - #92

Open
JVariance wants to merge 2 commits into
awcodes:3.xfrom
JVariance:split/brick-action-hook
Open

JVariance wants to merge 2 commits into
awcodes:3.xfrom
JVariance:split/brick-action-hook

Conversation

@JVariance

@JVariance JVariance commented Oct 31, 2026 •

Copy link
Copy Markdown

One of the small, general hooks you offered in #73. A brick configures its form's action in configureBrickAction(), but a field had no way to adjust it for its own context without touching every brick or copying BrickAction's internals.

Mason::make('content')
    ->brickAction(fn (Action $action): Action => $action
        ->slideOver()
        ->modalWidth(Width::ThreeExtraLarge))

The callback changes the $action it receives and may return it or null. It runs in BrickAction's bootUsing() right after the brick's configureBrickAction(), so the field gets the last word, since it knows the context. Filament ignores what bootUsing() returns, so a callback cannot swap in a new action; returning a different instance throws a LogicException rather than doing nothing. It also receives the brick's class as $brick and the action's $arguments (with mode being insert or edit), so it can differ per brick or per mode.

Our use case: a Mason field inside a brick's own form, whose brick forms should open beside the outer slide-over instead of over it (overlayParentActions() plus a class with merge: true). Today that needs a copy of the bootUsing() logic, which silently drifts whenever BrickAction::make() changes. Other uses: a slide-over or width per field, labels, or authorize().

Tests go through the Livewire action on insert and edit: the brick's configuration without a callback, the callback overriding it, a null return, the parameters passed, and saving with a customized action. Docs: "Brick form" in docs/fields/customizing.md.

🤖 Generated with Claude Code

A brick configures its form's action in configureBrickAction(), but a field
had no way to change it for its own context, e.g. a slide-over or a width,
without touching every brick. brickAction() takes a callback that runs after
the brick's configuration, like Filament's Repeater::addAction(). It receives
the action, the brick's class and the action's arguments; returning null
keeps the action.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@awcodes awcodes left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks. This is the kind of small, general hook I had in mind, and it runs in the right place, after the brick's own configureBrickAction().

One problem: Filament ignores the return value of bootUsing (CanBeBooted::boot()). So unlike Repeater::addAction(), a callback that returns a different Action instance does nothing. Only changing the action it was given takes effect. The docs and the description say "the callback receives the action and returns it", which leads people to the version that breaks.

Could you either:

  • change the docs to say the callback should modify the $action it receives, and return it or null; or
  • make a returned new instance actually take effect, if there's a clean way to do that within bootUsing?

Also, if #91 lands, a callback that sets afterFormFilled() would turn off the part lookup. I'll keep that in mind wherever those two meet.

…ferent one

Filament ignores what bootUsing() returns, so a callback that returned a new
action did nothing. The docs now say the callback changes the $action it
receives and may return it or null, and returning a different action throws
a LogicException instead of being silently dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JVariance

Copy link
Copy Markdown
Author

Went with the first option in bbd3d81. A new instance can't take effect cleanly: by the time bootUsing() runs, the action is already mounted, and copying a returned action's settings onto it would mean mirroring Filament's internals. So the docs now say the callback changes the $action it receives and may return it or null, and returning a different action throws a LogicException instead of being silently dropped. There's a test for that. Noted on #91 and afterFormFilled(); I'll follow up on whichever of the two lands second.

@JVariance
JVariance requested a review from awcodes October 31, 2026 18:01
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.

2 participants