{"record":{"id":"42b45413be4ab7f4","repo":"filamentphp/filament","slug":"you-cannot-use-the-enabletoolbarbuttons-method","errorCode":null,"errorMessage":"You cannot use the `enableToolbarButtons()` method when the toolbar buttons are dynamically returned from a function. Instead, return the enabled buttons from the function.","messagePattern":"You cannot use the `enableToolbarButtons\\(\\)` method when the toolbar buttons are dynamically returned from a function\\. Instead, return the enabled buttons from the function\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"packages/forms/src/Components/Concerns/InteractsWithToolbarButtons.php","lineNumber":53,"sourceCode":"        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        }\n\n        $this->toolbarButtonsModifications[] = [\n            'type' => 'enable',\n            'buttons' => $buttonsToEnable,\n        ];\n\n        return $this;\n    }\n\n    /**\n     * @param  array<int, string | object | array<int, string | object>> | Closure | null  $buttons\n     */\n    public function toolbarButtons(array | Closure | null $buttons): static\n    {\n        $this->toolbarButtons = $buttons;\n        $this->toolbarButtonsModifications = [];\n","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/filamentphp/filament/blob/53483fa9340e4ec637985fe454ebb58afb92ea24/packages/forms/src/Components/Concerns/InteractsWithToolbarButtons.php#L35-L71","documentation":"The mirror of `disableToolbarButtons()`: `enableToolbarButtons()` re-enables buttons against a statically configured toolbar list, which is meaningless when the list is produced by a Closure. Filament detects `toolbarButtons instanceof Closure` and throws a LogicException at configuration time, telling you to return the enabled buttons from the function instead.","triggerScenarios":"Chaining `->enableToolbarButtons(['codeBlock'])` onto a `RichEditor` configured with `->toolbarButtons(fn () => [...])`.","commonSituations":"Upgrading code that enabled extra buttons after the fact, then moving the toolbar config into a Closure for role-based toolbars without removing the enable call.","solutions":["Include the extra buttons in the Closure's return value.","If runtime enable/disable is required, use the static form `->toolbarButtons([...])`.","Push role logic into the Closure instead of stacking modification methods on top of it."],"exampleFix":"// before\nRichEditor::make('content')\n    ->toolbarButtons(fn (): array => ['bold', 'italic'])\n    ->enableToolbarButtons(['codeBlock']),\n\n// after\nRichEditor::make('content')\n    ->toolbarButtons(fn (): array => ['bold', 'italic', 'codeBlock']),","handlingStrategy":"validation","validationCode":"// Decide one strategy up front in shared field builders\n$field = RichEditor::make('content');\n\nif ($roleToolbarsEnabled) {\n    $field->toolbarButtons(fn (): array => ['bold', 'italic', 'codeBlock']); // include enabled set\n} else {\n    $field->toolbarButtons(['bold', 'italic'])\n        ->enableToolbarButtons(['codeBlock']);\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":["Fold extra buttons into the Closure's return list instead of enabling afterwards.","Audit shared field presets for enable calls before letting consumers pass Closures.","Treat the Closure vs modifications conflict as a design decision, not a toggle."],"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"}