filamentphp/filament · error · LogicException

You cannot use the `disableToolbarButtons()` method when the

Error message

You cannot use the `disableToolbarButtons()` method when the toolbar buttons are dynamically returned from a function. Instead, do not return the disabled buttons from the function.

What it means

A RichEditor's toolbar buttons can be configured statically (array) or dynamically (Closure evaluated at render time). `disableToolbarButtons()` records a modification against the static list; applying it to a Closure-provided list would be ambiguous, so Filament throws a LogicException immediately when the two are combined during field configuration.

Source

Thrown at packages/forms/src/Components/Concerns/InteractsWithToolbarButtons.php:36

     */
    protected array $toolbarButtonsModifications = [];

    public function disableAllToolbarButtons(bool $condition = true): static
    {
        if ($condition) {
            $this->toolbarButtonsModifications[] = ['type' => 'disableAll'];
        }

        return $this;
    }

    /**
     * @param  array<string | array<string>>  $buttonsToDisable
     */
    public function disableToolbarButtons(array $buttonsToDisable = []): static
    {
        if ($this->toolbarButtons instanceof Closure) {
            throw new LogicException('You cannot use the `disableToolbarButtons()` method when the toolbar buttons are dynamically returned from a function. Instead, do not return the disabled buttons from the function.');
        }

        $this->toolbarButtonsModifications[] = [
            'type' => 'disable',
            'buttons' => $buttonsToDisable,
        ];

        return $this;
    }

    /**
     * @param  array<string | object | array<string | object>>  $buttonsToEnable
     */
    public function enableToolbarButtons(array $buttonsToEnable = []): static
    {
        if ($this->toolbarButtons instanceof Closure) {
            throw new LogicException('You cannot use the `enableToolbarButtons()` method when the toolbar buttons are dynamically returned from a function. Instead, return the enabled buttons from the function.');
        }

View on GitHub (pinned to 53483fa934)

Solutions

  1. Move the filtering into the Closure: simply do not return the buttons you wanted disabled.
  2. If you need disable/enable semantics, switch back to a static array via `->toolbarButtons([...])`.
  3. In reusable components, accept an exclusion list as a parameter and consume it inside the Closure.

Example fix

// before
RichEditor::make('content')
    ->toolbarButtons(fn (): array => ['bold', 'italic', 'attachFiles'])
    ->disableToolbarButtons(['attachFiles']),

// after
RichEditor::make('content')
    ->toolbarButtons(fn (): array => ['bold', 'italic']),
Defensive patterns

Strategy: validation

Validate before calling

// Decide one strategy up front in shared field builders
$dynamicToolbar = $user->hasRole('editor');

$field = RichEditor::make('content');

if ($dynamicToolbar) {
    $field->toolbarButtons(fn (): array => array_values(array_diff(
        ['bold', 'italic', 'attachFiles'],
        ['attachFiles'], // exclusions applied inside the Closure
    )));
} else {
    $field->toolbarButtons(['bold', 'italic'])
        ->disableToolbarButtons(['attachFiles']);
}

Type guard

function usesDynamicToolbar(RichEditor $field): bool
{
    $reflection = new ReflectionProperty(RichEditor::class, 'toolbarButtons');
    $reflection->setAccessible(true);

    return $reflection->getValue($field) instanceof Closure;
}

Prevention

When it happens

Trigger: Chaining `->disableToolbarButtons(['attachFiles'])` onto a `RichEditor` that was configured with `->toolbarButtons(fn () => [...])` (a Closure).

Common situations: Refactoring a static per-role toolbar into a Closure and leaving the old `disableToolbarButtons()` call behind; shared field classes that call `disableToolbarButtons()` while users supply dynamic toolbars.

Related errors


AI-assisted analysis of filamentphp/filament@53483fa934 (2026-08-17). Data as JSON: /api/errors/cf42c57825a4320b. Report an issue: GitHub.