I followed the the great guide Audio block example with preview (honestly, I love your tutorials, they are great!) and it all works fine. But I stumbled across some unexpected behavior:
After I created an audio-block (and the built in picture block does the same) and uploaded a file but then delete this block, the file remains in the folder and on the server. I’ve read this thread on why this is more complex than first meets the eye. But another solution came to my mind: Why not - on delete - display a dialogue where associated files with the block could be selected for deletion?
How would I go about this, anyone have a hint on where to start?
Sadly, I don’t think this is an option to implement currently. Because your block itself won’t receive any callback or so when it is deleted. But the content data is just cut from the rest of the blocks array. And so there is no moment where your specific block has the chance to do some custom actions while being deleted.
I can understand where you’re coming from. At the same time this isn’t really a bug. As with other fields that can upload files to the page to directly reference them (e.g. files field, textarea field), those files still belong to the page afterwards and are not simply deleted because their reference gets removed from a field. You have to keep in mind that those files could also be referenced from another block/field.