Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-6424 - blocks - Adding a warning screen when the user clicks the …

…delete link.
  • Loading branch information...
commit 2b7ece005eb097bf23d5a8e35d665adec7b7986e 1 parent c92d6f4
@abgreeve abgreeve authored
Showing with 49 additions and 7 deletions.
  1. +2 −0  lang/en/block.php
  2. +47 −7 lib/blocklib.php
View
2  lang/en/block.php
@@ -37,6 +37,8 @@
$string['defaultregion_help'] = 'Themes may define one or more named block regions where blocks are displayed. This setting defines which of these you want this block to appear in by default. The region may be overridden on specific pages if required.';
$string['defaultweight'] = 'Default weight';
$string['defaultweight_help'] = 'The default weight allows you to choose roughly where you want the block to appear in the chosen region, either at the top or the bottom. The final location is calculated from all the blocks in that region (for example, only one block can actually be at the top). This value can be overridden on specific pages if required.';
+$string['deletecheck'] = 'Delete {$a} block?';
+$string['deleteblockcheck'] = 'Are you sure that you want to delete this block titled {$a}?';
$string['moveblockhere'] = 'Move block here';
$string['movingthisblockcancel'] = 'Moving this block ({$a})';
$string['onthispage'] = 'On this page';
View
54 lib/blocklib.php
@@ -1108,25 +1108,65 @@ public function process_url_add() {
* @return boolean true if anything was done. False if not.
*/
public function process_url_delete() {
+ global $CFG;
+
$blockid = optional_param('bui_deleteid', null, PARAM_INT);
+ $confirmdelete = optional_param('bui_confirm', null, PARAM_INT);
+
if (!$blockid) {
return false;
}
require_sesskey();
-
$block = $this->page->blocks->find_instance($blockid);
-
if (!$block->user_can_edit() || !$this->page->user_can_edit_blocks() || !$block->user_can_addto($this->page)) {
throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('deleteablock'));
}
- blocks_delete_instance($block->instance);
-
- // If the page URL was a guess, it will contain the bui_... param, so we must make sure it is not there.
- $this->page->ensure_param_not_in_url('bui_deleteid');
+ if (!$confirmdelete) {
+ $deletepage = new moodle_page();
+ $deletepage->set_pagelayout('admin');
+ $deletepage->set_course($this->page->course);
+ $deletepage->set_context($this->page->context);
+ if ($this->page->cm) {
+ $deletepage->set_cm($this->page->cm);
+ }
- return true;
+ $deleteurlbase = str_replace($CFG->wwwroot . '/', '/', $this->page->url->out_omit_querystring());
+ $deleteurlparams = $this->page->url->params();
+ $deletepage->set_url($deleteurlbase, $deleteurlparams);
+ $deletepage->set_block_actions_done();
+ // At this point we are either going to redirect, or display the form, so
+ // overwrite global $PAGE ready for this. (Formslib refers to it.)
+ $PAGE = $deletepage;
+ //some functions like MoodleQuickForm::addHelpButton use $OUTPUT so we need to replace that too
+ $output = $deletepage->get_renderer('core');
+ $OUTPUT = $output;
+
+ $site = get_site();
+ $blocktitle = $block->get_title();
+ $strdeletecheck = get_string('deletecheck', 'block', $blocktitle);
+ $message = get_string('deleteblockcheck', 'block', $blocktitle);
+
+ $PAGE->navbar->add($strdeletecheck);
+ $PAGE->set_title($blocktitle . ': ' . $strdeletecheck);
+ $PAGE->set_heading($site->fullname);
+ echo $OUTPUT->header();
+ $confirmurl = new moodle_url("$deletepage->url?", array('sesskey' => sesskey(), 'bui_deleteid' => $block->instance->id, 'bui_confirm' => 1));
+ $cancelurl = new moodle_url($deletepage->url);
+ $yesbutton = new single_button($confirmurl, get_string('yes'));
+ $nobutton = new single_button($cancelurl, get_string('no'));
+ echo $OUTPUT->confirm($message, $yesbutton, $nobutton);
+ echo $OUTPUT->footer();
+ // Make sure that nothing else happens after we have displayed this form.
+ exit;
+ } else {
+ blocks_delete_instance($block->instance);
+ // bui_deleteid and bui_confirm should not be in the PAGE url.
+ $this->page->ensure_param_not_in_url('bui_deleteid');
+ $this->page->ensure_param_not_in_url('bui_confirm');
+ return true;
+ }
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.