{"record":{"id":"cf42c57825a4320b","repo":"filamentphp/filament","slug":"you-cannot-use-the-disabletoolbarbuttons-metho","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"packages/forms/src/Components/Concerns/InteractsWithToolbarButtons.php","lineNumber":36,"sourceCode":"     */\n    protected array $toolbarButtonsModifications = [];\n\n    public function disableAllToolbarButtons(bool $condition = true): static\n    {\n        if ($condition) {\n            $this->toolbarButtonsModifications[] = ['type' => 'disableAll'];\n        }\n\n        return $this;\n    }\n\n    /**\n     * @param  array<string | array<string>>  $buttonsToDisable\n     */\n    public function disableToolbarButtons(array $buttonsToDisable = []): static\n    {\n        if ($this->toolbarButtons instanceof Closure) {\n            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.');\n        }\n\n        $this->toolbarButtonsModifications[] = [\n            'type' => 'disable',\n            'buttons' => $buttonsToDisable,\n        ];\n\n        return $this;\n    }\n\n    /**\n     * @param  array<string | object | array<string | object>>  $buttonsToEnable\n     */\n    public function enableToolbarButtons(array $buttonsToEnable = []): static\n    {\n        if ($this->toolbarButtons instanceof Closure) {\n            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.');\n        }","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/filamentphp/filament/blob/53483fa9340e4ec637985fe454ebb58afb92ea24/packages/forms/src/Components/Concerns/InteractsWithToolbarButtons.php#L18-L54","documentation":"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.","triggerScenarios":"Chaining `->disableToolbarButtons(['attachFiles'])` onto a `RichEditor` that was configured with `->toolbarButtons(fn () => [...])` (a Closure).","commonSituations":"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.","solutions":["Move the filtering into the Closure: simply do not return the buttons you wanted disabled.","If you need disable/enable semantics, switch back to a static array via `->toolbarButtons([...])`.","In reusable components, accept an exclusion list as a parameter and consume it inside the Closure."],"exampleFix":"// before\nRichEditor::make('content')\n    ->toolbarButtons(fn (): array => ['bold', 'italic', 'attachFiles'])\n    ->disableToolbarButtons(['attachFiles']),\n\n// after\nRichEditor::make('content')\n    ->toolbarButtons(fn (): array => ['bold', 'italic']),","handlingStrategy":"validation","validationCode":"// Decide one strategy up front in shared field builders\n$dynamicToolbar = $user->hasRole('editor');\n\n$field = RichEditor::make('content');\n\nif ($dynamicToolbar) {\n    $field->toolbarButtons(fn (): array => array_values(array_diff(\n        ['bold', 'italic', 'attachFiles'],\n        ['attachFiles'], // exclusions applied inside the Closure\n    )));\n} else {\n    $field->toolbarButtons(['bold', 'italic'])\n        ->disableToolbarButtons(['attachFiles']);\n}","typeGuard":"function usesDynamicToolbar(RichEditor $field): bool\n{\n    $reflection = new ReflectionProperty(RichEditor::class, 'toolbarButtons');\n    $reflection->setAccessible(true);\n\n    return $reflection->getValue($field) instanceof Closure;\n}","tryCatchPattern":null,"preventionTips":["Never stack disable/enable calls on a toolbar configured with a Closure.","Keep exclusions as data consumed inside the dynamic Closure in shared components.","When refactoring static toolbars to dynamic, grep for disableToolbarButtons/enableToolbarButtons."],"tags":["filament","rich-editor","toolbar","configuration-conflict","forms"],"backgroundTag":"conflicting-configuration-methods","analyzedSha":"53483fa9340e4ec637985fe454ebb58afb92ea24","analyzedAt":"2026-08-17T02:06:23.049Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}