Injecting headerActions to Resource
Hi, im making my own plugin that has a custom class page, and i have a filament page in the /edit route that extends my custom class page.
But i want to not override the method getHeaderActions() in my filament page, and i want that the EditPage class can add actions to header.
Is this possible in any chance?
11 Replies
You don’t need to inject it. Use getHeaderActions() but return a merged array with the parent actions.
thanks for the reply! yes i know i can do this, but i want to leave the logic to the default getHeaderActions() method, and inject under the hood my others actions.
Maybe I’m just misunderstanding but it will default as long as you don’t overload the method. It will all flow down hill, so as long as you merge the parent class actions in then the default functionality from the parent will still be valid.
yes, but i don't want to write every time parent::getHeaderActions() etc in all my pages.
sorry if I'm not making myself understood xd
Sorry, if I’m not understanding it either. Lol.😂
If you need to reuse it then you could make it a trait.
i want to make a EditPage similar to EditRecord or CreateRecord, but i want that the user can create his own (an example) App\Filament\Resources\CatResource\Pages\CatPage and only by extends his class with my class EditPage can view others header actions, and the user can add his own header action calling the method getHeaderActions(). I was looking for the trait Filament\Pages\Concerns\InteractsWithHeaderActions that handle the header actions, and there is no change to "inject" other action under the hood 😭 .
If they extend your EditPage, then it’s up to them to include the parent actions or not. I don’t feel that’s the responsibility of your page in your plugin.
yes but the actions that i want to show are the core actions of my plugin, but nvm i will probably follow your first reply. Thanks a lot!
Fair, enough, but if they are extending your page, then it’s really out of your hands what they do with it. 🤷
I achieved this by manipulating the $this->cachedHeaderActions array which is used to display the actions on the page. But I don't know if it's a good solution
If it does what you need it then so be it. I would be hesitant to do anything with the cached actions, personally, unless you fully understand how they work. And, no I don’t fully understand them myself. 🤣