diff --git a/course/lib.php b/course/lib.php index 0673aded462..02407606e79 100644 --- a/course/lib.php +++ b/course/lib.php @@ -3832,16 +3832,6 @@ function include_course_ajax($course, $usedmodules = array(), $enabledmodules = )), null, true); } - // Include blocks dragdrop - $params = array( - 'courseid' => $course->id, - 'pagetype' => $PAGE->pagetype, - 'pagelayout' => $PAGE->pagelayout, - 'subpage' => $PAGE->subpage, - 'regions' => $PAGE->blocks->get_regions(), - ); - $PAGE->requires->yui_module('moodle-core-blocks', 'M.core_blocks.init_dragdrop', array($params), null, true); - // Require various strings for the command toolbox $PAGE->requires->strings_for_js(array( 'moveleft', diff --git a/lib/ajax/blocks.php b/lib/ajax/blocks.php index 470106d071c..ab2452587ad 100644 --- a/lib/ajax/blocks.php +++ b/lib/ajax/blocks.php @@ -30,6 +30,7 @@ require_once(dirname(__FILE__) . '/../../config.php'); $courseid = required_param('courseid', PARAM_INT); $pagelayout = required_param('pagelayout', PARAM_ALPHAEXT); $pagetype = required_param('pagetype', PARAM_ALPHAEXT); +$contextid = required_param('contextid', PARAM_INT); $subpage = optional_param('subpage', '', PARAM_ALPHANUMEXT); $cmid = optional_param('cmid', null, PARAM_INT); $action = optional_param('action', '', PARAM_ALPHA); @@ -50,9 +51,33 @@ if (!is_null($cmid)) { require_login($courseid, false, $cm); require_sesskey(); +// Set context from ID, so we don't have to guess it from other info. +$PAGE->set_context(context::instance_by_id($contextid)); + // Setting layout to replicate blocks configuration for the page we edit $PAGE->set_pagelayout($pagelayout); $PAGE->set_subpage($subpage); +$pagetype = explode('-', $pagetype); +switch ($pagetype[0]) { + case 'my': + // My Home page needs to have 'content' block region set up. + $PAGE->set_blocks_editing_capability('moodle/my:manageblocks'); + $PAGE->blocks->add_region('content'); + break; + case 'user': + if ($pagelayout == 'mydashboard') { + // User profile pages also need the 'content' block region set up. + $PAGE->blocks->add_region('content'); + // If it's not the current user's profile, we need a different capability. + if ($PAGE->context->contextlevel == CONTEXT_USER && $PAGE->context->instanceid != $USER->id) { + $PAGE->set_blocks_editing_capability('moodle/user:manageblocks'); + } else { + $PAGE->set_blocks_editing_capability('moodle/user:manageownblocks'); + } + } + break; +} + echo $OUTPUT->header(); // send headers switch ($action) { diff --git a/lib/outputrequirementslib.php b/lib/outputrequirementslib.php index d4eff1ccc2a..8c97eac4e80 100644 --- a/lib/outputrequirementslib.php +++ b/lib/outputrequirementslib.php @@ -282,6 +282,22 @@ class page_requirements_manager { if ($page->pagelayout === 'frametop') { $this->js_init_call('M.util.init_frametop'); } + + // Include block drag/drop if editing is on + if ($page->user_is_editing()) { + $params = array( + 'courseid' => $page->course->id, + 'pagetype' => $page->pagetype, + 'pagelayout' => $page->pagelayout, + 'subpage' => $page->subpage, + 'regions' => $page->blocks->get_regions(), + 'contextid' => $page->context->id, + ); + if (!empty($page->cm->id)) { + $params['cmid'] = $page->cm->id; + } + $page->requires->yui_module('moodle-core-blocks', 'M.core_blocks.init_dragdrop', array($params), null, true); + } } /** diff --git a/lib/yui/blocks/blocks.js b/lib/yui/blocks/blocks.js index edb655fa048..baa06be254c 100644 --- a/lib/yui/blocks/blocks.js +++ b/lib/yui/blocks/blocks.js @@ -10,7 +10,9 @@ YUI.add('moodle-core-blocks', function(Y) { LIGHTBOX : 'lightbox', REGIONCONTENT : 'region-content', SKIPBLOCK : 'skip-block', - SKIPBLOCKTO : 'skip-block-to' + SKIPBLOCKTO : 'skip-block-to', + MYINDEX : 'page-my-index', + REGIONMAIN : 'region-main' } var DRAGBLOCK = function() { @@ -26,6 +28,15 @@ YUI.add('moodle-core-blocks', function(Y) { this.samenodeclass = CSS.BLOCK; this.parentnodeclass = CSS.REGIONCONTENT; + // Add relevant classes and ID to 'content' block region on My Home page. + var myhomecontent = Y.Node.all('body#'+CSS.MYINDEX+' #'+CSS.REGIONMAIN+' > .'+CSS.REGIONCONTENT); + if (myhomecontent.size() > 0) { + var contentregion = myhomecontent.item(0); + contentregion.addClass(CSS.BLOCKREGION); + contentregion.set('id', CSS.REGIONCONTENT); + contentregion.one('div').addClass(CSS.REGIONCONTENT); + } + // Initialise blocks dragging // Find all block regions on the page var blockregionlist = Y.Node.all('div.'+CSS.BLOCKREGION); @@ -42,17 +53,18 @@ YUI.add('moodle-core-blocks', function(Y) { var regioncontent = Y.Node.create('
') .addClass(CSS.REGIONCONTENT); blockregion.appendChild(regioncontent); + var pre = blockregionlist.filter('#region-pre'); + var post = blockregionlist.filter('#region-post'); - var regionid = this.get_region_id(blockregionlist.item(0)); - if (regionid === 'post') { + if (pre.size() === 0 && post.size() === 1) { // pre block is missing, instert it before post blockregion.setAttrs({id : 'region-pre'}); - blockregionlist.item(0).insert(blockregion, 'before'); + post.item(0).insert(blockregion, 'before'); blockregionlist.unshift(blockregion); - } else { + } else if (post.size() === 0 && pre.size() === 1) { // post block is missing, instert it after pre blockregion.setAttrs({id : 'region-post'}); - blockregionlist.item(0).insert(blockregion, 'after'); + pre.item(0).insert(blockregion, 'after'); blockregionlist.push(blockregion); } } @@ -214,6 +226,7 @@ YUI.add('moodle-core-blocks', function(Y) { pagelayout : this.get('pagelayout'), pagetype : this.get('pagetype'), subpage : this.get('subpage'), + contextid : this.get('contextid'), action : 'move', bui_moveid : this.get_block_id(dragnode), bui_newregion : this.get_block_region(dropnode) @@ -263,6 +276,9 @@ YUI.add('moodle-core-blocks', function(Y) { cmid : { value : null }, + contextid : { + value : null + }, pagelayout : { value : null }, diff --git a/user/profile.php b/user/profile.php index 54d65f21dd7..9439c4e8338 100644 --- a/user/profile.php +++ b/user/profile.php @@ -377,8 +377,9 @@ if (!isset($hiddenfields['suspended'])) { echo ""; - +echo '
'; echo $OUTPUT->blocks_for_region('content'); +echo '
'; // Print messaging link if allowed if (isloggedin() && has_capability('moodle/site:sendmessage', $context)