Is duplicate() function necessary in the block's controller?

Permalink 1 user found helpful
I was looking at writing a duplicate() function in the block's controller. I went through C5's Slideshow block as it seems to be a simple block to study. I commented out the duplicate() function in the concrete/core/controllers/blocks/slideshow.php and it still seems to work perfectly. When I edit the block, it correctly inserts a new bID on both tables when "Custom Slideshow" type is selected. It also works fine with versioning when I go back to the previous versions.

I think save() function generates a new bID every time a block is saved/edited. The save() function already has the INSERT statement for the second table. Then why do we still need the duplicate() function?

BlueFractals
 
mnakalay replied on at Permalink Reply
mnakalay
The duplicate function is necessary mostly with add-ons that need to save in more than one table.

The slideshow add-on for instance will save settings in one table and a list of images in another table. The data will be linked through the bID field.

When you edit your block, the save function deals with the two tables. However, sometimes, the bID of the block will change without you editing so it will not go through the save function. Without the duplicate function, wWhat would happen is that the new bID would be saved in the main table but it would not be saved in the secondary table which means the slideshow would not show any image.

An example of when the duplicate code is called is I think when you apply a template. Another is if you copy the block in the clipboard and paste it somewhere else.

Remember, add-ons are only aware of the main table, any other table has to be dealt woth manually.