From 8325c83b20b337a9517501b879194f004a3df06c Mon Sep 17 00:00:00 2001 From: Mikhail Golenkov Date: Wed, 9 Dec 2020 12:02:20 +1100 Subject: [PATCH] MDL-68792 theme_boost: Show the fake blocks on embedded layout. --- lib/outputcomponents.php | 9 ++++++++ lib/outputrenderers.php | 20 ++++++++++++----- lib/tests/outputcomponents_test.php | 29 ++++++++++++++++++++++++ theme/boost/config.php | 3 ++- theme/boost/layout/embedded.php | 8 +++++-- theme/boost/scss/moodle/blocks.scss | 30 +++++++++++++++++++++++++ theme/boost/style/moodle.css | 21 +++++++++++++++++ theme/boost/templates/embedded.mustache | 24 +++++++++++++++----- theme/classic/style/moodle.css | 21 +++++++++++++++++ 9 files changed, 152 insertions(+), 13 deletions(-) diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index b6277cb1cf8..ff5428b9978 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -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'; + } } diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 6b61cab00f6..e2e5770c0c7 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -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 ''; } diff --git a/lib/tests/outputcomponents_test.php b/lib/tests/outputcomponents_test.php index c46383b7456..0ff1c55c392 100644 --- a/lib/tests/outputcomponents_test.php +++ b/lib/tests/outputcomponents_test.php @@ -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()); + } } diff --git a/theme/boost/config.php b/theme/boost/config.php index 613162f554f..89525838e70 100644 --- a/theme/boost/config.php +++ b/theme/boost/config.php @@ -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. diff --git a/theme/boost/layout/embedded.php b/theme/boost/layout/embedded.php index 5469e1bf5b5..762d7f3277c 100644 --- a/theme/boost/layout/embedded.php +++ b/theme/boost/layout/embedded.php @@ -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); diff --git a/theme/boost/scss/moodle/blocks.scss b/theme/boost/scss/moodle/blocks.scss index 7a9d4bfc8da..95ac0b7fbe1 100644 --- a/theme/boost/scss/moodle/blocks.scss +++ b/theme/boost/scss/moodle/blocks.scss @@ -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%; + } + } +} diff --git a/theme/boost/style/moodle.css b/theme/boost/style/moodle.css index 5241ce349bf..a4a8b9a73a5 100644 --- a/theme/boost/style/moodle.css +++ b/theme/boost/style/moodle.css @@ -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; } diff --git a/theme/boost/templates/embedded.mustache b/theme/boost/templates/embedded.mustache index 5d7a26de705..a9a419f03e9 100644 --- a/theme/boost/templates/embedded.mustache +++ b/theme/boost/templates/embedded.mustache @@ -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": "", + "htmlattributes": "The attributes that should be added to the tag", "page_title": "Test page", "favicon": "favicon.ico", - "main_content": "

Headings make html validators happier

" - } + "standard_head_html": "The standard tags that should be included in the 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 tag", + "main_content": "

Headings make html validators happier

", + "standard_end_of_body_html": "The standard tags that should be output after everything else" + }, + "hasfakeblocks": true, + "fakeblocks": "

Fake blocks html goes here

" } }} {{{ output.doctype }}} @@ -45,10 +54,15 @@ {{> core/local/toast/wrapper}} {{{ output.standard_top_of_body_html }}} -
-
+
+ {{#hasfakeblocks}} +
+ {{{ fakeblocks }}} +
+ {{/hasfakeblocks}} +
{{{ output.main_content }}} -
+
{{{ output.standard_end_of_body_html }}} diff --git a/theme/classic/style/moodle.css b/theme/classic/style/moodle.css index 0f07f2b31f5..1c0f8769101 100644 --- a/theme/classic/style/moodle.css +++ b/theme/classic/style/moodle.css @@ -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; }