I'm trying to work on a module to move photos from one particular album (the "Import" album) into other albums based on their dates. Obviously I'd like to try and prevent the user from deleting the Import album to make the code robust. Unfortunately I'm not sure how to make Gallery abort a pending deletion. The below sample code demonstrates what I want to do:
static function item_before_delete($itembd) {
/* Catch deletion of the Import album */
$import_album = module::get_var("calendar_auto_structure","import_location");
if ($itembd->is_album()) {
if ($itembd->id==$import_album) {
// Do something here to abort deletion.
// Display a warning
message::error(t("Cannot delete album because it is being used for import."));
}
}
}
I'm just not sure what code I need to do to tell Gallery to abort the deletion. I can't seem to find any other similar examples of this situation in other modules either. Can somebody please point me in the right direction?
Posts: 27300
// Do something here to abort deletion.
you could just return to the page the user is on I guess. Is that what you want to do?
url::redirect($item->url());
Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team
Posts: 120
I didn't think of that but unfortunately it doesn't work because Gallery shows the Confirm Delete form/dialog beforehand. As a result, the redirect takes place in that dialog box. Since my post, I've found the following interesting snippets.
In the Gallery module within ./models/item.php I noticed in function "delete" there is code regarding the deletion of the root album:
I feel this is a step closer to the desired outcome, but again it doesn't really work cleanly (that dialog seems to get in the way, and probably because I don't really understand what the code is doing).
Also in ./helpers/item.php there is a function called get_delete_form, which actually returns the code to display the Confirm Delete form.
I may just have to keep hunting around in the code.
Posts: 120
I can't see any obvious way around this and I'm not familiar enough with the framework or Gallery to deal with the problem nicely. An ugly solution is something like:
Posts: 27300
I can't think of another way.
Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team