forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-81597 theme_boost: Fix header bar alignment
- Refactot context_header class to implement named templatable so render_context_header in core and theme_boost can be removed - Refactor context_header to use templates - Fix context header layout and styles
- Loading branch information
Showing
8 changed files
with
149 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
issueNumber: MDL-81597 | ||
notes: | ||
theme: | ||
- message: New `core/contextheader` mustache template has been added. This template can be overridden by themes to modify the context header | ||
type: improved |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
*/ | ||
|
||
use core\output\local\action_menu\subpanel; | ||
use core\output\named_templatable; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
|
@@ -4109,7 +4110,7 @@ public function export_for_template(renderer_base $output) { | |
* @copyright 2015 Adrian Greeve <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class context_header implements renderable { | ||
class context_header implements renderable, named_templatable { | ||
|
||
/** | ||
* @var string $heading Main heading. | ||
|
@@ -4190,6 +4191,57 @@ protected function format_button_images() { | |
array('class' => $class)); | ||
} | ||
} | ||
|
||
/** | ||
* Export for template. | ||
* | ||
* @param renderer_base $output Renderer. | ||
* @return array | ||
*/ | ||
public function export_for_template(renderer_base $output): array { | ||
// Heading. | ||
$headingtext = isset($this->heading) ? $this->heading : $output->get_page()->heading; | ||
$heading = $output->heading($headingtext, $this->headinglevel, "h2 mb-0"); | ||
|
||
// Buttons. | ||
if (isset($this->additionalbuttons)) { | ||
$additionalbuttons = []; | ||
foreach ($this->additionalbuttons as $button) { | ||
if (!isset($button->page)) { | ||
// Include js for messaging. | ||
if ($button['buttontype'] === 'togglecontact') { | ||
\core_message\helper::togglecontact_requirejs(); | ||
} | ||
if ($button['buttontype'] === 'message') { | ||
\core_message\helper::messageuser_requirejs(); | ||
} | ||
} | ||
foreach ($button['linkattributes'] as $key => $value) { | ||
$button['attributes'][] = ['name' => $key, 'value' => $value]; | ||
} | ||
$additionalbuttons[] = $button; | ||
} | ||
} | ||
|
||
return [ | ||
'heading' => $heading, | ||
'headinglevel' => $this->headinglevel, | ||
'imagedata' => $this->imagedata, | ||
'prefix' => $this->prefix, | ||
'hasadditionalbuttons' => !empty($additionalbuttons), | ||
'additionalbuttons' => $additionalbuttons ?? [], | ||
]; | ||
} | ||
|
||
/** | ||
* Get the template name. | ||
* | ||
* @param renderer_base $renderer Renderer. | ||
* @return string | ||
*/ | ||
public function get_template_name(renderer_base $renderer): string { | ||
return 'core/contextheader'; | ||
} | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{{! | ||
This file is part of Moodle - http://moodle.org/ | ||
Moodle is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Moodle is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
}} | ||
{{! | ||
@template core/contextheader | ||
Context header template. | ||
Example context (json): | ||
{ | ||
"heading": "<h2>Page title</h2>", | ||
"prefix": "Page prefix", | ||
"hasadditionalbuttons": true, | ||
"additionalbuttons": [ | ||
{ | ||
"url": "http://example.com", | ||
"title": "Button title", | ||
"formattedimage": "http://example.com/image.jpg", | ||
"attributes": [ | ||
{ | ||
"name": "data-attribute", | ||
"value": "attribute value" | ||
}, | ||
{ | ||
"name": "class", | ||
"value": "btn btn-primary" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}} | ||
<div class="page-context-header d-flex align-items-center mb-2"> | ||
{{#imagedata}} | ||
<div class="page-header-image"> | ||
{{{imagedata}}} | ||
</div> | ||
{{/imagedata}} | ||
<div class="page-header-headings"> | ||
{{#prefix}} | ||
<div class="text-muted text-uppercase small line-height-3"> | ||
{{{prefix}}} | ||
</div> | ||
{{/prefix}} | ||
{{{heading}}} | ||
</div> | ||
{{#hasadditionalbuttons}} | ||
<div class="btn-group header-button-group mx-3"> | ||
{{#additionalbuttons}} | ||
<a href="{{url}}" {{#attributes}} {{name}}="{{value}}" {{/attributes}}> | ||
{{#page}} | ||
{{#pix}}{{formattedimage}}{{/pix}} | ||
<span class="header-button-title">{{title}}</span> | ||
{{/page}} | ||
{{^page}} | ||
<img src="{{formattedimage}}" alt="{{title}}"> | ||
{{/page}} | ||
</a> | ||
{{/additionalbuttons}} | ||
</div> | ||
{{/hasadditionalbuttons}} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters