Skip to content

Commit

Permalink
MDL-55445 theme: Clean and More automatically use the branding logos
Browse files Browse the repository at this point in the history
But in order to maintain smooth backwards compatibility, the logos
set in the themes themselves take precedence.
  • Loading branch information
Frederic Massart committed Aug 17, 2016
1 parent 2258b4d commit aa6b412
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
40 changes: 37 additions & 3 deletions theme/clean/classes/core_renderer.php
Expand Up @@ -56,7 +56,8 @@ protected function should_render_logo($headinglevel = 1) {

// 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;
}
Expand All @@ -76,11 +77,11 @@ protected function should_render_logo($headinglevel = 1) {
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'));

Expand Down Expand Up @@ -118,4 +119,37 @@ protected function get_home_ref($returnlink = true) {

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);
}

}
4 changes: 2 additions & 2 deletions theme/clean/lang/en/theme_clean.php
Expand Up @@ -57,7 +57,7 @@
$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';

Expand All @@ -68,4 +68,4 @@
$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.';
3 changes: 2 additions & 1 deletion theme/clean/lib.php
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions theme/more/lang/en/theme_more.php
Expand Up @@ -64,7 +64,7 @@
$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';

Expand All @@ -76,7 +76,7 @@
$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.';

3 changes: 2 additions & 1 deletion theme/more/lib.php
Expand Up @@ -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.
Expand Down

0 comments on commit aa6b412

Please sign in to comment.