From: samhemelryk Date: Fri, 11 Sep 2009 06:00:32 +0000 (+0000) Subject: blocklib MDL-20207 Added $CFG->undeletableblocktypes and documented in config-dist X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5afbd0e783e85dce17920372ab322a63fab755a9;p=moodle.git blocklib MDL-20207 Added $CFG->undeletableblocktypes and documented in config-dist --- diff --git a/config-dist.php b/config-dist.php index c9797d713a..37e4b11203 100644 --- a/config-dist.php +++ b/config-dist.php @@ -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 diff --git a/lib/blocklib.php b/lib/blocklib.php index 98c2fde956..3d203ec49e 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -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()) {