Skip to content

Commit

Permalink
MDL-30669 - blocks: Added a warning when deleting blocks that have mu…
Browse files Browse the repository at this point in the history
…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
abgreeve committed Feb 26, 2013
1 parent 1dd6835 commit 3dd204b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
20 changes: 11 additions & 9 deletions course/lib.php
Expand Up @@ -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')
);
}

/**
Expand Down
1 change: 1 addition & 0 deletions lang/en/block.php
Expand Up @@ -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';
Expand Down
21 changes: 21 additions & 0 deletions lib/blocklib.php
Expand Up @@ -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);
Expand Down

0 comments on commit 3dd204b

Please sign in to comment.