From 3dd204b1e6738ed51fe066976c9f2e6d25206e72 Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Thu, 3 Jan 2013 14:22:53 +0800 Subject: [PATCH] MDL-30669 - blocks: Added a warning when deleting blocks that have multiple displays set. Also added a fix to the function course_page_type_list(). It was making a call to get_context_info_array() which will generate an error if $currentcontext is not set. --- course/lib.php | 20 +++++++++++--------- lang/en/block.php | 1 + lib/blocklib.php | 21 +++++++++++++++++++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/course/lib.php b/course/lib.php index 5b901b2005af6..26070909b4d49 100644 --- a/course/lib.php +++ b/course/lib.php @@ -3684,16 +3684,18 @@ protected function notify($touser, $fromuser, $name='courserequested', $subject, * @param stdClass $currentcontext Current context of block */ function course_page_type_list($pagetype, $parentcontext, $currentcontext) { - // if above course context ,display all course fomats - list($currentcontext, $course, $cm) = get_context_info_array($currentcontext->id); - if ($course->id == SITEID) { - return array('*'=>get_string('page-x', 'pagetype')); - } else { - return array('*'=>get_string('page-x', 'pagetype'), - 'course-*'=>get_string('page-course-x', 'pagetype'), - 'course-view-*'=>get_string('page-course-view-x', 'pagetype') - ); + // $currentcontext could be null, get_context_info_array() will throw an error if this is the case. + if (isset($currentcontext)) { + // if above course context ,display all course fomats + list($currentcontext, $course, $cm) = get_context_info_array($currentcontext->id); + if ($course->id == SITEID) { + return array('*'=>get_string('page-x', 'pagetype')); + } } + return array('*'=>get_string('page-x', 'pagetype'), + 'course-*'=>get_string('page-course-x', 'pagetype'), + 'course-view-*'=>get_string('page-course-view-x', 'pagetype') + ); } /** diff --git a/lang/en/block.php b/lang/en/block.php index 8e7d0c00e88bc..eefb901376b47 100644 --- a/lang/en/block.php +++ b/lang/en/block.php @@ -42,6 +42,7 @@ $string['deletecheck'] = 'Delete {$a} block?'; $string['deleteblock'] = 'Delete {$a} block'; $string['deleteblockcheck'] = 'Are you sure that you want to delete this block titled {$a}?'; +$string['deleteblockwarning'] = '

You are about to delete a block that appears elsewhere.

Original block location: {$a->location}
Display on page types: {$a->pagetype}

Are you sure you want to continue?

'; $string['hideblock'] = 'Hide {$a} block'; $string['hidedockpanel'] = 'Hide the dock panel'; $string['hidepanel'] = 'Hide panel'; diff --git a/lib/blocklib.php b/lib/blocklib.php index 5066ae557b7b1..f37441425e07f 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -1176,6 +1176,27 @@ public function process_url_delete() { $strdeletecheck = get_string('deletecheck', 'block', $blocktitle); $message = get_string('deleteblockcheck', 'block', $blocktitle); + // If the block is being shown in sub contexts display a warning. + if ($block->instance->showinsubcontexts == 1) { + $parentcontext = context::instance_by_id($block->instance->parentcontextid); + $systemcontext = context_system::instance(); + $messagestring = new stdClass(); + $messagestring->location = $parentcontext->get_context_name(); + + // Checking for blocks that may have visibility on the front page and pages added on that. + if ($parentcontext->id != $systemcontext->id && is_inside_frontpage($parentcontext)) { + $messagestring->pagetype = get_string('showonfrontpageandsubs', 'block'); + } else { + $pagetypes = generate_page_type_patterns($this->page->pagetype, $parentcontext); + $messagestring->pagetype = $block->instance->pagetypepattern; + if (isset($pagetypes[$block->instance->pagetypepattern])) { + $messagestring->pagetype = $pagetypes[$block->instance->pagetypepattern]; + } + } + + $message = get_string('deleteblockwarning', 'block', $messagestring); + } + $PAGE->navbar->add($strdeletecheck); $PAGE->set_title($blocktitle . ': ' . $strdeletecheck); $PAGE->set_heading($site->fullname);