MDL-41511 blocks: improved how custom block regions were being rendered.
There is a new theme property 'blockrendermethod' that can be set by the theme in its config.php and tells Moodle what method it is using to render blocks in the layout files. Either blocks, or blocks_for_region. Then when adding custom block regions to a page content we ensure we use the same method the theme is using elsewhere. This is really a hack becuase we (I) didn't properly deprecate blocks_for_region when I added the blocks method. Conflicts: lib/outputlib.php
This commit is contained in:
+34
-1
@@ -356,6 +356,13 @@ class theme_config {
|
||||
*/
|
||||
private $usesvg = null;
|
||||
|
||||
/**
|
||||
* Sets the render method that should be used for rendering custom block regions by scripts such as my/index.php
|
||||
* Defaults to {@link core_renderer::blocks_for_region()}
|
||||
* @var string
|
||||
*/
|
||||
public $blockrendermethod = null;
|
||||
|
||||
/**
|
||||
* Load the config.php file for a particular theme, and return an instance
|
||||
* of this class. (That is, this is a factory method.)
|
||||
@@ -424,7 +431,7 @@ class theme_config {
|
||||
$configurable = array('parents', 'sheets', 'parents_exclude_sheets', 'plugins_exclude_sheets', 'javascripts', 'javascripts_footer',
|
||||
'parents_exclude_javascripts', 'layouts', 'enable_dock', 'enablecourseajax', 'supportscssoptimisation',
|
||||
'rendererfactory', 'csspostprocess', 'editor_sheets', 'rarrow', 'larrow', 'hidefromselector', 'doctype',
|
||||
'yuicssmodules', 'blockrtlmanipulations');
|
||||
'yuicssmodules', 'blockrtlmanipulations', 'blockrendermethod');
|
||||
|
||||
foreach ($config as $key=>$value) {
|
||||
if (in_array($key, $configurable)) {
|
||||
@@ -1642,6 +1649,32 @@ class theme_config {
|
||||
public function get_theme_name() {
|
||||
return get_string('pluginname', 'theme_'.$this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the block render method.
|
||||
*
|
||||
* It is set by the theme via:
|
||||
* $THEME->blockrendermethod = '...';
|
||||
*
|
||||
* It can be one of two values, blocks or blocks_for_region.
|
||||
* It should be set to the method being used by the theme layouts.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_block_render_method() {
|
||||
if ($this->blockrendermethod) {
|
||||
// Return the specified block render method.
|
||||
return $this->blockrendermethod;
|
||||
}
|
||||
// Its not explicitly set, check the parent theme configs.
|
||||
foreach ($this->parent_configs as $config) {
|
||||
if (isset($config->blockrendermethod)) {
|
||||
return $config->blockrendermethod;
|
||||
}
|
||||
}
|
||||
// Default it to blocks.
|
||||
return 'blocks';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3237,6 +3237,28 @@ EOD;
|
||||
return html_writer::tag($tag, $content, $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a custom block region.
|
||||
*
|
||||
* Use this method if you want to add an additional block region to the content of the page.
|
||||
* Please note this should only be used in special situations.
|
||||
* We want to leave the theme is control where ever possible!
|
||||
*
|
||||
* This method must use the same method that the theme uses within its layout file.
|
||||
* As such it asks the theme what method it is using.
|
||||
* It can be one of two values, blocks or blocks_for_region (deprecated).
|
||||
*
|
||||
* @param string $regionname The name of the custom region to add.
|
||||
* @return string HTML for the block region.
|
||||
*/
|
||||
public function custom_block_region($regionname) {
|
||||
if ($this->page->theme->get_block_render_method() === 'blocks') {
|
||||
return $this->blocks($regionname);
|
||||
} else {
|
||||
return $this->blocks_for_region($regionname);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the CSS classes to apply to the body tag.
|
||||
*
|
||||
|
||||
@@ -357,6 +357,9 @@ M.core.blockdraganddrop.is_using_blocks_render_method = function() {
|
||||
var goodregions = Y.all('.block-region[data-blockregion]').size();
|
||||
var allregions = Y.all('.block-region').size();
|
||||
this._isusingnewblocksmethod = (allregions === goodregions);
|
||||
if (goodregions > 0 && allregions > 0) {
|
||||
Y.log('Both core_renderer::blocks and core_renderer::blocks_for_region have been used.', 'warn', 'moodle-core_blocks');
|
||||
}
|
||||
}
|
||||
return this._isusingnewblocksmethod;
|
||||
};
|
||||
@@ -371,8 +374,10 @@ M.core.blockdraganddrop.is_using_blocks_render_method = function() {
|
||||
*/
|
||||
M.core.blockdraganddrop.init = function(params) {
|
||||
if (this.is_using_blocks_render_method()) {
|
||||
Y.log('Block drag and drop initialised for the blocks method.', 'info', 'moodle-core_blocks');
|
||||
new MANAGER(params);
|
||||
} else {
|
||||
Y.log('Block drag and drop initialised with the legacy manager (blocks_for_region used).', 'info', 'moodle-core_blocks');
|
||||
new DRAGBLOCK(params);
|
||||
}
|
||||
};
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -357,6 +357,8 @@ M.core.blockdraganddrop.is_using_blocks_render_method = function() {
|
||||
var goodregions = Y.all('.block-region[data-blockregion]').size();
|
||||
var allregions = Y.all('.block-region').size();
|
||||
this._isusingnewblocksmethod = (allregions === goodregions);
|
||||
if (goodregions > 0 && allregions > 0) {
|
||||
}
|
||||
}
|
||||
return this._isusingnewblocksmethod;
|
||||
};
|
||||
|
||||
Vendored
+5
@@ -355,6 +355,9 @@ M.core.blockdraganddrop.is_using_blocks_render_method = function() {
|
||||
var goodregions = Y.all('.block-region[data-blockregion]').size();
|
||||
var allregions = Y.all('.block-region').size();
|
||||
this._isusingnewblocksmethod = (allregions === goodregions);
|
||||
if (goodregions > 0 && allregions > 0) {
|
||||
Y.log('Both core_renderer::blocks and core_renderer::blocks_for_region have been used.', 'warn', 'moodle-core_blocks');
|
||||
}
|
||||
}
|
||||
return this._isusingnewblocksmethod;
|
||||
};
|
||||
@@ -369,8 +372,10 @@ M.core.blockdraganddrop.is_using_blocks_render_method = function() {
|
||||
*/
|
||||
M.core.blockdraganddrop.init = function(params) {
|
||||
if (this.is_using_blocks_render_method()) {
|
||||
Y.log('Block drag and drop initialised for the blocks method.', 'info', 'moodle-core_blocks');
|
||||
new MANAGER(params);
|
||||
} else {
|
||||
Y.log('Block drag and drop initialised with the legacy manager (blocks_for_region used).', 'info', 'moodle-core_blocks');
|
||||
new DRAGBLOCK(params);
|
||||
}
|
||||
};
|
||||
|
||||
+1
-1
@@ -152,6 +152,6 @@ if ($currentpage->userid == 0) {
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
echo $OUTPUT->blocks_for_region('content');
|
||||
echo $OUTPUT->custom_block_region('content');
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
+1
-1
@@ -63,6 +63,6 @@ $PAGE->set_subpage($currentpage->id);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
echo $OUTPUT->blocks_for_region('content');
|
||||
echo $OUTPUT->custom_block_region('content');
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
@@ -174,3 +174,6 @@ $THEME->hidefromselector = true;
|
||||
/** List of javascript files that need to included on each page */
|
||||
$THEME->javascripts = array();
|
||||
$THEME->javascripts_footer = array();
|
||||
|
||||
// Set this to the method you will use in your layout files for
|
||||
$THEME->blockrendermethod = 'blocks_for_region';
|
||||
|
||||
+2
-3
@@ -413,9 +413,8 @@ if (!empty($CFG->enablebadges)) {
|
||||
|
||||
echo html_writer::end_tag('dl');
|
||||
echo "</div></div>"; // Closing desriptionbox and userprofilebox.
|
||||
echo '<div id="region-content" class="block-region"><div class="region-content">';
|
||||
echo $OUTPUT->blocks_for_region('content');
|
||||
echo '</div></div>';
|
||||
|
||||
echo $OUTPUT->custom_block_region('content');
|
||||
|
||||
// Print messaging link if allowed
|
||||
if (isloggedin() && has_capability('moodle/site:sendmessage', $context)
|
||||
|
||||
+1
-1
@@ -58,6 +58,6 @@ $PAGE->set_subpage($currentpage->id);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
echo $OUTPUT->blocks_for_region('content');
|
||||
echo $OUTPUT->custom_block_region('content');
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
Reference in New Issue
Block a user