Determine if a Block was Added or Edited
Permalink
Hi all, I have a question for you C5 gurus.
I'm building a package that includes a few block types. In one of the block types, I need to execute some code ONLY WHEN THE BLOCK IS FIRST ADDED, but not when an existing block is edited and saved.
I'm not talking about running the code in the add.php & edit.php forms - I want to run the code when the block is saved.
It seems natural that my code should go in the block controller's save() function, but how can I determine if the save() call is the first time the block is being saved (an "add") or a subsequent save (an "edit")?
Is there a magic function like on_add() I can add in my controller? or what's the best way to approach this?
Thanks in advance for any advice.
I'm building a package that includes a few block types. In one of the block types, I need to execute some code ONLY WHEN THE BLOCK IS FIRST ADDED, but not when an existing block is edited and saved.
I'm not talking about running the code in the add.php & edit.php forms - I want to run the code when the block is saved.
It seems natural that my code should go in the block controller's save() function, but how can I determine if the save() call is the first time the block is being saved (an "add") or a subsequent save (an "edit")?
Is there a magic function like on_add() I can add in my controller? or what's the best way to approach this?
Thanks in advance for any advice.
It looks like
I'm surprised there's not a method in the BlockController class for accessing this property - say, $controller->isSaved(). Maybe it can be added in the future? This solution is a bit clunky.