F
Filament2y ago
sm

Add dehydrateStateUsing to Builder\Block

I have a builder that I'm using to store related data on a Form, adding a dehydrateStateUsing to the builder works, but I want to have each block manage it's own dehydrated state to keep things a little bit more modular.. but adding a dehydrateStateUsing to the Block doesn't seem to work (never gets called). I've also tried accessing ->blocks() and running getState() on them within the builder, but that doesn't trigger the dehydrateStateUsing callback either. The docs state that whenever getState() is called the dehydrateStateUsing is called.. but that doesn't seem to be the case for Blocks? Any pointers?
5 Replies
Patrick Boivin
I can confirm, dehydrateStateUsing() is called at the Builder level and for each field in a Block, but not fot the Block itself. I think it makes sense conceptually, if you think of a Block as a group of fields. I think the simplest option is probably to roll you own logic inside of the Builder's dehydrateStateUsing() to map each block's data to a transformer (custom class or method).
sm
smOP2y ago
Was hoping I wouldn't have to do that, but so be it 🙂
Patrick Boivin
Could be an interesting PR if you have some time... just saying 😜
sm
smOP2y ago
If PRd, I think this would have to apply to other "layout" components as well.. Don't think it makes sense to have a special case for Block.. I don't think dehydrateStateUsing works on Section, Group etc either (just tried) And if Block is basically a layout field, then atleast its consistent right now 🙂
awcodes
awcodes2y ago
A layout component doesn’t have ‘state’

Did you find this page helpful?