Preventing blocks from being deleted

Preventing blocks from being deleted

by Tim Hunt -
Number of replies: 0
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

In Moodle 2.x, the admin can mark certain types of block so that they can never be deleted. By default, this is used to make it impossible to delete the settings or the navigation blocks. If you delete those, you can be stuck as there is no way to turn editing back on, and add them back.

(If you did not know about this, go to Admin -> Plugins -> Blocks -> Manage blocks, and look for the padlock icons.)

Now that is great if you are an admin who has just set up a really complex blocks configuration, and you don't want anyone to mess it up. However, the way the code works is not that simple. The rules that were implemented were actually:

A block cannot be deleted if ALL of these are true:

  1. The type of block is protected on the manage blocks page;
  2. The block's parent context is the system context; and
  3. The block is set to show on all pages, or just on the site index page.

We (the Open University) don't see any benefit to having conditions 2. and 3. We have some blocks that are set to show up on all pages for type course-view-*, and idiots keep deleting them!

Therefore, I have raised MDL-35964 to propose changing how this features works, so that if a type of block is set to be undeletable, then really no one can delete it.

If someone really need to delete one of those blocks, then the admin can temporarily un-protect it while it is added or deleted, and then it can be protected again (or not).

Anyway, that is what we would like to do, but we would like you feedback about whether it is a good idea or not. Please comment in this forum thread, on in the tracker issue.

Average of ratings: -