Permalink
Browse files

MDL-30669 - blocks: Added a warning when deleting blocks that have mu…

…ltiple 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.
  • Loading branch information...
1 parent 1dd6835 commit 3dd204b1e6738ed51fe066976c9f2e6d25206e72 @abgreeve abgreeve committed Jan 3, 2013
Showing with 33 additions and 9 deletions.
  1. +11 −9 course/lib.php
  2. +1 −0 lang/en/block.php
  3. +21 −0 lib/blocklib.php
View
20 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')
+ );
}
/**
View
1 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'] = '<p>You are about to delete a block that appears elsewhere.</p><p>Original block location: {$a->location}<br />Display on page types: {$a->pagetype}</p><p>Are you sure you want to continue?</p>';
$string['hideblock'] = 'Hide {$a} block';
$string['hidedockpanel'] = 'Hide the dock panel';
$string['hidepanel'] = 'Hide panel';
View
21 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);

0 comments on commit 3dd204b

Please sign in to comment.