MDL-55747 theme_noname: Display logos in the different pages

Part of MDL-55071
This commit is contained in:
Frederic Massart 2016-08-29 12:03:13 +08:00 committed by Dan Poltawski
parent fa02f6e6bf
commit b71c82adb8
6 changed files with 118 additions and 4 deletions

View File

@ -32,6 +32,7 @@ use single_button;
use single_select;
use paging_bar;
use url_select;
use context_course;
defined('MOODLE_INTERNAL') || die;
@ -76,6 +77,64 @@ class core_renderer extends \core_renderer {
return $this->render_from_template('core/navbar', $this->page->navbar);
}
/**
* Override to inject the logo.
*
* @param array $headerinfo The header info.
* @param int $headinglevel What level the 'h' tag will be.
* @return string HTML for the header bar.
*/
public function context_header($headerinfo = null, $headinglevel = 1) {
global $SITE;
if ($this->should_display_main_logo($headinglevel)) {
$sitename = format_string($SITE->fullname, true, array('context' => context_course::instance(SITEID)));
return html_writer::div(html_writer::empty_tag('img', [
'src' => $this->get_logo_url(null, 75), 'alt' => $sitename]), 'logo');
}
return parent::context_header($headerinfo, $headinglevel);
}
/**
* Get the compact logo URL.
*
* @return string
*/
public function get_compact_logo_url($maxwidth = 100, $maxheight = 100) {
return parent::get_compact_logo_url(null, 43);
}
/**
* Whether we should display the main logo.
*
* @return bool
*/
public function should_display_main_logo($headinglevel = 1) {
global $PAGE;
// Only render the logo if we're on the front page or login page and the we have a logo.
$logo = $this->get_logo_url();
if ($headinglevel == 1 && !empty($logo)) {
if ($PAGE->pagelayout == 'frontpage' || $PAGE->pagelayout == 'login') {
return true;
}
}
return false;
}
/**
* Whether we should display the logo in the navbar.
*
* We will when there are no main logos, and we have compact logo.
*
* @return bool
*/
public function should_display_navbar_logo() {
$logo = $this->get_compact_logo_url();
return !empty($logo) && !$this->should_display_main_logo();
}
/*
* Overriding the custom_menu function ensures the custom menu is
* always shown, even if no menu items are configured in the global

View File

@ -1615,6 +1615,26 @@ img#persona_signin {
}
.breadcrumb-nav .breadcrumb {
margin: 0;
}
/** Navbar */
.navbar-brand {
.logo {
display: inline-block;
margin-top: -$navbar-brand-padding-y;
}
.site-name {
display: inline-block;
margin-left: $spacer/2;
}
height: 43px;
}
/** Page header */
#page-header {
.logo {
margin: $spacer 0;
}
}
/** Header-bar styles **/

View File

@ -15,7 +15,16 @@
<div class="clearfix">
<button class="navbar-toggler pull-xs-right hidden-sm-up" data-toggle="collapse" data-target="#bd-main-mav">☰<span class="sr-only">{{#str}}expand{{/str}}</span></button>
</div>
<a class="navbar-brand" href="{{{ config.wwwroot }}}">{{{ sitename }}}</a>
<a href="{{{ config.wwwroot }}}" class="navbar-brand">
{{# output.should_display_navbar_logo }}
<div class="logo">
<img src="{{output.get_compact_logo_url}}" alt={{#quote}}{{sitename}}{{/quote}}>
</div>
{{/ output.should_display_navbar_logo }}
<div class="site-name">{{{ sitename }}}</div>
</a>
<!-- user_menu -->
{{{ output.user_menu }}}

View File

@ -15,7 +15,16 @@
<div class="clearfix">
<button class="navbar-toggler pull-xs-right hidden-sm-up" data-toggle="collapse" data-target="#bd-main-mav">☰<span class="sr-only">{{#str}}expand{{/str}}</span></button>
</div>
<a class="navbar-brand" href="{{{ config.wwwroot }}}">{{{ sitename }}}</a>
<a href="{{{ config.wwwroot }}}" class="navbar-brand">
{{# output.should_display_navbar_logo }}
<div class="logo">
<img src="{{output.get_compact_logo_url}}" alt={{#quote}}{{sitename}}{{/quote}}>
</div>
{{/ output.should_display_navbar_logo }}
<div class="site-name">{{{ sitename }}}</div>
</a>
<!-- user_menu -->
{{{ output.user_menu }}}

View File

@ -15,7 +15,16 @@
<div class="clearfix">
<button class="navbar-toggler pull-xs-right hidden-sm-up" data-toggle="collapse" data-target="#bd-main-mav">☰<span class="sr-only">{{#str}}expand{{/str}}</span></button>
</div>
<a class="navbar-brand" href="{{{ config.wwwroot }}}">{{{ sitename }}}</a>
<a href="{{{ config.wwwroot }}}" class="navbar-brand">
{{# output.should_display_navbar_logo }}
<div class="logo">
<img src="{{output.get_compact_logo_url}}" alt={{#quote}}{{sitename}}{{/quote}}>
</div>
{{/ output.should_display_navbar_logo }}
<div class="site-name">{{{ sitename }}}</div>
</a>
<!-- user_menu -->
{{{ output.user_menu }}}

View File

@ -15,7 +15,15 @@
<div class="clearfix">
<button class="navbar-toggler pull-xs-right hidden-sm-up" data-toggle="collapse" data-target="#bd-main-mav">☰<span class="sr-only">{{#str}}expand{{/str}}</span></button>
</div>
<a class="navbar-brand" href="{{{ config.wwwroot }}}">{{{ sitename }}}</a>
<a href="{{{ config.wwwroot }}}" class="navbar-brand">
{{# output.should_display_navbar_logo }}
<div class="logo">
<img src="{{output.get_compact_logo_url}}" alt={{#quote}}{{sitename}}{{/quote}}>
</div>
{{/ output.should_display_navbar_logo }}
<div class="site-name">{{{ sitename }}}</div>
</a>
<div class="collapse navbar-toggleable-xs" id="bd-main-nav">
<nav class="nav navbar-nav">