]> git.mjollnir.org Git - moodle.git/commitdiff
blocklib MDL-20207 Added $CFG->undeletableblocktypes and documented in config-dist
authorsamhemelryk <samhemelryk>
Fri, 11 Sep 2009 06:00:32 +0000 (06:00 +0000)
committersamhemelryk <samhemelryk>
Fri, 11 Sep 2009 06:00:32 +0000 (06:00 +0000)
config-dist.php
lib/blocklib.php

index c9797d713a81f6c10f64ad76242906040a341924..37e4b1120318e613ae2c081d0230128f36519868 100644 (file)
@@ -172,6 +172,11 @@ $CFG->admin = 'admin';
 // These blocks are used when no other default setting is found.
 //      $CFG->defaultblocks = 'participants,activity_modules,search_forums,admin,course_list:news_items,calendar_upcoming,recent_activity';
 //
+// The blocks in this list will be protected from deletion, and this is primarily
+// used to protect the navigation and settings blocks which can be very hard to
+// get back if accidentally delete.
+//      $CFG->undeletableblocktypes = 'global_navigation_tree,settings_navigation_tree';
+//
 // You can specify a different class to be created for the $PAGE global, and to
 // compute which blocks appear on each page. However, I cannot think of any good
 // reason why you would need to change that. It just felt wrong to hard-code the
index 98c2fde956ba1348240fd77150b28928b727f727..3d203ec49e3ede30372615d8c06405c8c1bd9d1b 100644 (file)
@@ -877,6 +877,12 @@ class block_manager {
     public function edit_controls($block) {
         global $CFG;
 
+        if (!isset($CFG->undeletableblocktypes) || (!is_array($CFG->undeletableblocktypes) && !is_string($CFG->undeletableblocktypes))) {
+            $CFG->undeletableblocktypes = array('global_navigation_tree','settings_navigation_tree');
+        } else if (is_string($CFG->undeletableblocktypes)) {
+            $CFG->undeletableblocktypes = explode(',', $CFG->undeletableblocktypes);
+        }
+
         $controls = array();
         $actionurl = $this->page->url->out(false, array('sesskey'=> sesskey()), false);
 
@@ -905,9 +911,11 @@ class block_manager {
         }
 
         if ($this->page->user_can_edit_blocks() && $block->user_can_edit() && $block->user_can_addto($this->page)) {
-            // Delete icon.
-            $controls[] = array('url' => $actionurl . '&bui_deleteid=' . $block->instance->id,
-                    'icon' => 't/delete', 'caption' => get_string('delete'));
+            if (!in_array($block->instance->blockname, $CFG->undeletableblocktypes)) {
+                // Delete icon.
+                $controls[] = array('url' => $actionurl . '&bui_deleteid=' . $block->instance->id,
+                        'icon' => 't/delete', 'caption' => get_string('delete'));
+            }
         }
 
         if ($this->page->user_can_edit_blocks()) {