MDL-55445 theme: Clean and More automatically use the branding logos

But in order to maintain smooth backwards compatibility, the logos
set in the themes themselves take precedence.
This commit is contained in:
Frederic Massart
2016-08-17 10:26:31 +08:00
parent 2258b4dc41
commit aa6b41293f
5 changed files with 45 additions and 9 deletions
+37 -3
View File
@@ -56,7 +56,8 @@ class theme_clean_core_renderer extends theme_bootstrapbase_core_renderer {
// Only render the logo if we're on the front page or login page
// and the theme has a logo.
if ($headinglevel == 1 && !empty($this->page->theme->settings->logo)) {
$logo = $this->get_logo_url();
if ($headinglevel == 1 && !empty($logo)) {
if ($PAGE->pagelayout == 'frontpage' || $PAGE->pagelayout == 'login') {
return true;
}
@@ -76,11 +77,11 @@ class theme_clean_core_renderer extends theme_bootstrapbase_core_renderer {
public function navbar_home($returnlink = true) {
global $CFG;
if ($this->should_render_logo() || empty($this->page->theme->settings->smalllogo)) {
$imageurl = $this->get_compact_logo_url(null, 35);
if ($this->should_render_logo() || empty($imageurl)) {
// If there is no small logo we always show the site name.
return $this->get_home_ref($returnlink);
}
$imageurl = $this->page->theme->setting_file_url('smalllogo', 'smalllogo');
$image = html_writer::img($imageurl, get_string('sitelogo', 'theme_' . $this->page->theme->name),
array('class' => 'small-logo'));
@@ -118,4 +119,37 @@ class theme_clean_core_renderer extends theme_bootstrapbase_core_renderer {
return html_writer::tag('span', $sitename, array('class' => 'brand'));
}
/**
* Return the theme logo URL, else the site's logo URL, if any.
*
* Note that maximum sizes are not applied to the theme logo.
*
* @param int $maxwidth The maximum width, or null when the maximum width does not matter.
* @param int $maxheight The maximum height, or null when the maximum height does not matter.
* @return moodle_url|false
*/
public function get_logo_url($maxwidth = null, $maxheight = 100) {
if (!empty($this->page->theme->settings->logo)) {
return $this->page->theme->setting_file_url('logo', 'logo');
}
return parent::get_logo_url($maxwidth, $maxheight);
}
/**
* Return the theme's compact logo URL, else the site's compact logo URL, if any.
*
* Note that maximum sizes are not applied to the theme logo.
*
* @param int $maxwidth The maximum width, or null when the maximum width does not matter.
* @param int $maxheight The maximum height, or null when the maximum height does not matter.
* @return moodle_url|false
*/
public function get_compact_logo_url($maxwidth = 100, $maxheight = 100) {
if (!empty($this->page->theme->settings->smalllogo)) {
return $this->page->theme->setting_file_url('smalllogo', 'smalllogo');
}
return parent::get_compact_logo_url($maxwidth, $maxheight);
}
}
+2 -2
View File
@@ -57,7 +57,7 @@ $string['invert'] = 'Invert navbar';
$string['invertdesc'] = 'Swaps text and background for the navbar at the top of the page between black and white.';
$string['logo'] = 'Logo';
$string['logodesc'] = 'The logo is only displayed in the header of the front page and login page.<br /> If the height of your logo is more than 75px add div.logo {height: 100px;} to the Custom CSS box below, amending accordingly if the height is other than 100px.';
$string['logodesc'] = 'The logo is only displayed in the header of the front page and login page.<br /> If the height of your logo is more than 75px add div.logo {height: 100px;} to the Custom CSS box below, amending accordingly if the height is other than 100px. Note that when not set, the logo from \'Appearance > Branding\' will be used.';
$string['pluginname'] = 'Clean';
@@ -68,4 +68,4 @@ $string['sitelogo'] = 'Site logo';
$string['sitename'] = 'Display site name along with small logo';
$string['sitenamedesc'] = 'If there is no small logo, the site name is always displayed in the navigation bar. If a small logo is set, it may be displayed with or without the site name.';
$string['smalllogo'] = 'Small logo';
$string['smalllogodesc'] = 'The small logo is displayed in the navigation bar. If there is a header logo for the front page and login page, the small logo is not displayed on these pages.';
$string['smalllogodesc'] = 'The small logo is displayed in the navigation bar. If there is a header logo for the front page and login page, the small logo is not displayed on these pages. Note that when not set, the compact logo from \'Appearance > Branding\' will be used.';
+2 -1
View File
@@ -38,9 +38,10 @@
* @return string The parsed CSS The parsed CSS.
*/
function theme_clean_process_css($css, $theme) {
global $OUTPUT;
// Set the background image for the logo.
$logo = $theme->setting_file_url('logo', 'logo');
$logo = $OUTPUT->get_logo_url(null, 75);
$css = theme_clean_set_logo($css, $logo);
// Set custom CSS.
+2 -2
View File
@@ -64,7 +64,7 @@ $string['invertdesc'] = 'Swaps text and background for the navbar at the top of
$string['linkcolor'] = 'Link colour';
$string['linkcolor_desc'] = 'The colour of the links.';
$string['logo'] = 'Logo';
$string['logodesc'] = 'The logo is only displayed in the header of the front page and login page.<br /> If the height of your logo is more than 75px add div.logo {height: 100px;} to the Custom CSS box below, amending accordingly if the height is other than 100px.';
$string['logodesc'] = 'The logo is only displayed in the header of the front page and login page.<br /> If the height of your logo is more than 75px add div.logo {height: 100px;} to the Custom CSS box below, amending accordingly if the height is other than 100px. Note that when not set, the logo from \'Appearance > Branding\' will be used.';
$string['pluginname'] = 'More';
@@ -76,7 +76,7 @@ $string['sitelogo'] = 'Site logo';
$string['sitename'] = 'Display site name along with small logo';
$string['sitenamedesc'] = 'If there is no small logo, the site name is always displayed in the navigation bar. If a small logo is set, it may be displayed with or without the site name.';
$string['smalllogo'] = 'Small logo';
$string['smalllogodesc'] = 'The small logo is displayed in the navigation bar. If there is a header logo for the front page and login page, the small logo is not displayed on these pages.';
$string['smalllogodesc'] = 'The small logo is displayed in the navigation bar. If there is a header logo for the front page and login page, the small logo is not displayed on these pages. Note that when not set, the compact logo from \'Appearance > Branding\' will be used.';
$string['textcolor'] = 'Text colour';
$string['textcolor_desc'] = 'The colour of the text.';
+2 -1
View File
@@ -99,9 +99,10 @@ function theme_more_less_variables($theme) {
* @return string The parsed CSS The parsed CSS.
*/
function theme_more_process_css($css, $theme) {
global $OUTPUT;
// Set the background image for the logo.
$logo = $theme->setting_file_url('logo', 'logo');
$logo = $OUTPUT->get_logo_url(null, 100);
$css = theme_more_set_logo($css, $logo);
// Set custom CSS.