MDL-68792 theme_boost: Show the fake blocks on embedded layout.

This commit is contained in:
Mikhail Golenkov 2020-12-09 12:02:20 +11:00
parent 4ec279a2f0
commit 8325c83b20
9 changed files with 152 additions and 13 deletions

View File

@ -3407,6 +3407,15 @@ class block_contents {
public function add_class($class) {
$this->attributes['class'] .= ' '.$class;
}
/**
* Check if the block is a fake block.
*
* @return boolean
*/
public function is_fake() {
return isset($this->attributes['data-block']) && $this->attributes['data-block'] == '_fake';
}
}

View File

@ -1817,9 +1817,10 @@ class core_renderer extends renderer_base {
* Output all the blocks in a particular region.
*
* @param string $region the name of a region on this page.
* @param boolean $fakeblocksonly Output fake block only.
* @return string the HTML to be output.
*/
public function blocks_for_region($region) {
public function blocks_for_region($region, $fakeblocksonly = false) {
$blockcontents = $this->page->blocks->get_content_for_region($region, $this);
$lastblock = null;
$zones = array();
@ -1832,6 +1833,10 @@ class core_renderer extends renderer_base {
foreach ($blockcontents as $bc) {
if ($bc instanceof block_contents) {
if ($fakeblocksonly && !$bc->is_fake()) {
// Skip rendering real blocks if we only want to show fake blocks.
continue;
}
$output .= $this->block($bc, $region);
$lastblock = $bc->title;
} else if ($bc instanceof block_move_target) {
@ -3939,9 +3944,12 @@ EOD;
*
* @since Moodle 2.5.1 2.6
* @param string $region The region to get HTML for.
* @param array $classes Wrapping tag classes.
* @param string $tag Wrapping tag.
* @param boolean $fakeblocksonly Include fake blocks only.
* @return string HTML.
*/
public function blocks($region, $classes = array(), $tag = 'aside') {
public function blocks($region, $classes = array(), $tag = 'aside', $fakeblocksonly = false) {
$displayregion = $this->page->apply_theme_region_manipulations($region);
$classes = (array)$classes;
$classes[] = 'block-region';
@ -3952,7 +3960,7 @@ EOD;
'data-droptarget' => '1'
);
if ($this->page->blocks->region_has_content($displayregion, $this)) {
$content = $this->blocks_for_region($displayregion);
$content = $this->blocks_for_region($displayregion, $fakeblocksonly);
} else {
$content = '';
}
@ -5084,9 +5092,10 @@ class core_renderer_maintenance extends core_renderer {
* @param string $region
* @param array $classes
* @param string $tag
* @param boolean $fakeblocksonly
* @return string
*/
public function blocks($region, $classes = array(), $tag = 'aside') {
public function blocks($region, $classes = array(), $tag = 'aside', $fakeblocksonly = false) {
return '';
}
@ -5094,9 +5103,10 @@ class core_renderer_maintenance extends core_renderer {
* Does nothing. The maintenance renderer cannot produce blocks.
*
* @param string $region
* @param boolean $fakeblocksonly Output fake block only.
* @return string
*/
public function blocks_for_region($region) {
public function blocks_for_region($region, $fakeblocksonly = false) {
return '';
}

View File

@ -650,4 +650,33 @@ EOF;
$this->assertTrue(in_array(['name' => 'class', 'value' => $labelclass], $data->labelattributes));
$this->assertTrue(in_array(['name' => 'style', 'value' => $labelstyle], $data->labelattributes));
}
/**
* Data provider for test_block_contents_is_fake().
*
* @return array
*/
public function block_contents_is_fake_provider() {
return [
'Null' => [null, false],
'Not set' => [false, false],
'Fake' => ['_fake', true],
'Real block' => ['activity_modules', false],
];
}
/**
* Test block_contents is_fake() method.
*
* @dataProvider block_contents_is_fake_provider
* @param mixed $value Value for the data-block attribute
* @param boolean $expected The expected result
*/
public function test_block_contents_is_fake($value, $expected) {
$bc = new block_contents(array());
if ($value !== false) {
$bc->attributes['data-block'] = $value;
}
$this->assertEquals($expected, $bc->is_fake());
}
}

View File

@ -112,7 +112,8 @@ $THEME->layouts = [
// Embeded pages, like iframe/object embeded in moodleform - it needs as much space as possible.
'embedded' => array(
'file' => 'embedded.php',
'regions' => array()
'regions' => array('side-pre'),
'defaultregion' => 'side-pre',
),
// Used during upgrade and install, and for the 'This site is undergoing maintenance' message.
// This must not have any blocks, links, or API calls that would lead to database or cache interaction.

View File

@ -24,9 +24,13 @@
defined('MOODLE_INTERNAL') || die();
$fakeblockshtml = $OUTPUT->blocks('side-pre', array(), 'aside', true);
$hasfakeblocks = strpos($fakeblockshtml, 'data-block="_fake"') !== false;
$templatecontext = [
'sitename' => format_string($SITE->shortname, true, ['context' => context_course::instance(SITEID), "escape" => false]),
'output' => $OUTPUT
'output' => $OUTPUT,
'hasfakeblocks' => $hasfakeblocks,
'fakeblocks' => $fakeblockshtml,
];
echo $OUTPUT->render_from_template('theme_boost/embedded', $templatecontext);

View File

@ -374,3 +374,33 @@ body.drawer-open-left #region-main.has-blocks {
border: 2px dashed $gray-800;
margin: 4px 0;
}
.pagelayout-embedded {
.has-fake-blocks {
padding: 1rem;
display: flex;
}
.has-fake-blocks .embedded-main {
order: 0;
width: calc(100% - #{$blocks-column-width});
margin-right: 1rem;
}
.embedded-blocks {
order: 1;
width: $blocks-column-width;
}
@media (max-width: 767.98px) {
.has-fake-blocks {
display: block;
}
.has-fake-blocks .embedded-main {
width: 100%;
}
.embedded-blocks {
width: 100%;
}
}
}

View File

@ -12775,6 +12775,27 @@ input[disabled] {
border: 2px dashed #343a40;
margin: 4px 0; }
.pagelayout-embedded .has-fake-blocks {
padding: 1rem;
display: flex; }
.pagelayout-embedded .has-fake-blocks .embedded-main {
order: 0;
width: calc(100% - 360px);
margin-right: 1rem; }
.pagelayout-embedded .embedded-blocks {
order: 1;
width: 360px; }
@media (max-width: 767.98px) {
.pagelayout-embedded .has-fake-blocks {
display: block; }
.pagelayout-embedded .has-fake-blocks .embedded-main {
width: 100%; }
.pagelayout-embedded .embedded-blocks {
width: 100%; } }
.navbar {
max-height: 50px; }

View File

@ -21,15 +21,24 @@
Context variables required for this template:
* output - The core renderer for the page
* hasfakeblocks - true if there are fake blocks on this page
* fakeblocks - HTML for the fake blocks
Example context (json):
{
"output": {
"doctype": "<!DOCTYPE html>",
"htmlattributes": "The attributes that should be added to the <html> tag",
"page_title": "Test page",
"favicon": "favicon.ico",
"main_content": "<h1>Headings make html validators happier</h1>"
}
"standard_head_html": "The standard tags that should be included in the <head> tag",
"body_attributes": "The attributes to use within the body tag",
"standard_top_of_body_html": "The standard tags that should be output just inside the start of the <body> tag",
"main_content": "<h1>Headings make html validators happier</h1>",
"standard_end_of_body_html": "The standard tags that should be output after everything else"
},
"hasfakeblocks": true,
"fakeblocks": "<h2>Fake blocks html goes here</h2>"
}
}}
{{{ output.doctype }}}
@ -45,10 +54,15 @@
{{> core/local/toast/wrapper}}
{{{ output.standard_top_of_body_html }}}
<div id="page">
<div id="page-content" class="d-block">
<div id="page" {{#hasfakeblocks}}class="has-fake-blocks"{{/hasfakeblocks}}>
{{#hasfakeblocks}}
<section class="embedded-blocks" aria-label="{{#str}}blocks{{/str}}">
{{{ fakeblocks }}}
</section>
{{/hasfakeblocks}}
<section class="embedded-main">
{{{ output.main_content }}}
</div>
</section>
</div>
{{{ output.standard_end_of_body_html }}}
</body>

View File

@ -12989,6 +12989,27 @@ input[disabled] {
border: 2px dashed #343a40;
margin: 4px 0; }
.pagelayout-embedded .has-fake-blocks {
padding: 1rem;
display: flex; }
.pagelayout-embedded .has-fake-blocks .embedded-main {
order: 0;
width: calc(100% - 360px);
margin-right: 1rem; }
.pagelayout-embedded .embedded-blocks {
order: 1;
width: 360px; }
@media (max-width: 767.98px) {
.pagelayout-embedded .has-fake-blocks {
display: block; }
.pagelayout-embedded .has-fake-blocks .embedded-main {
width: 100%; }
.pagelayout-embedded .embedded-blocks {
width: 100%; } }
.navbar {
max-height: 50px; }