Skip to content

Commit

Permalink
MDL-50661 theme_clean: New small logo setting
Browse files Browse the repository at this point in the history
Introduces new settings to set a small logo in the navbar next
to the site name on pages where the logo is not displayed.
  • Loading branch information
David Monllao committed Nov 30, 2015
1 parent c18acb8 commit c08b52a
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 16 deletions.
54 changes: 54 additions & 0 deletions theme/clean/classes/core_renderer.php
Expand Up @@ -64,4 +64,58 @@ protected function should_render_logo($headinglevel = 1) {

return false;
}

/**
* Returns the navigation bar home reference.
*
* The small logo is only rendered on pages where the logo is not displayed.
*
* @param bool $returnlink Whether to wrap the icon and the site name in links or not
* @return string The site name, the small logo or both depending on the theme settings.
*/
public function navbar_home($returnlink = true) {
global $CFG;

if ($this->should_render_logo() || empty($this->page->theme->settings->smalllogo)) {
// 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'));

if ($returnlink) {
$logocontainer = html_writer::link($CFG->wwwroot, $image,
array('class' => 'small-logo-container', 'title' => get_string('home')));
} else {
$logocontainer = html_writer::tag('span', $image, array('class' => 'small-logo-container'));
}

// Sitename setting defaults to true.
if (!isset($this->page->theme->settings->sitename) || !empty($this->page->theme->settings->sitename)) {
return $logocontainer . $this->get_home_ref($returnlink);
}

return $logocontainer;
}

/**
* Returns a reference to the site home.
*
* It can be either a link or a span.
*
* @param bool $returnlink
* @return string
*/
protected function get_home_ref($returnlink = true) {
global $CFG, $SITE;

$sitename = format_string($SITE->shortname, true, array('context' => context_course::instance(SITEID)));

if ($returnlink) {
return html_writer::link($CFG->wwwroot, $sitename, array('class' => 'brand', 'title' => get_string('home')));
}

return html_writer::tag('span', $sitename, array('class' => 'brand'));
}
}
5 changes: 5 additions & 0 deletions theme/clean/lang/en/theme_clean.php
Expand Up @@ -64,3 +64,8 @@
$string['region-side-post'] = 'Right';
$string['region-side-pre'] = 'Left';

$string['sitelogo'] = 'Site logo';
$string['sitename'] = 'Display site name along with small logo';
$string['sitenamedesc'] = 'This setting is only applied if a "Small logo" is set. If no small logo is set the site name is always displayed in the navigation bar, but if it is you can use this setting to display it or not.';
$string['smalllogo'] = 'Small logo';
$string['smalllogodesc'] = 'This logo is displayed in the navbar next to the site name, if a "Logo" is set, then it is only displayed on the pages where the logo is not displayed.';
4 changes: 1 addition & 3 deletions theme/clean/layout/columns1.php
Expand Up @@ -41,9 +41,7 @@
<header role="banner" class="navbar navbar-fixed-top<?php echo $html->navbarclass ?> moodle-has-zindex">
<nav role="navigation" class="navbar-inner">
<div class="container-fluid">
<a class="brand" href="<?php echo $CFG->wwwroot;?>"><?php echo
format_string($SITE->shortname, true, array('context' => context_course::instance(SITEID)));
?></a>
<?php echo $OUTPUT->navbar_home(); ?>
<?php echo $OUTPUT->navbar_button(); ?>
<?php echo $OUTPUT->user_menu(); ?>
<div class="nav-collapse collapse">
Expand Down
4 changes: 1 addition & 3 deletions theme/clean/layout/columns2.php
Expand Up @@ -50,9 +50,7 @@
<header role="banner" class="navbar navbar-fixed-top<?php echo $html->navbarclass ?> moodle-has-zindex">
<nav role="navigation" class="navbar-inner">
<div class="container-fluid">
<a class="brand" href="<?php echo $CFG->wwwroot;?>"><?php echo
format_string($SITE->shortname, true, array('context' => context_course::instance(SITEID)));
?></a>
<?php echo $OUTPUT->navbar_home(); ?>
<?php echo $OUTPUT->navbar_button(); ?>
<?php echo $OUTPUT->user_menu(); ?>
<div class="nav-collapse collapse">
Expand Down
4 changes: 1 addition & 3 deletions theme/clean/layout/columns3.php
Expand Up @@ -60,9 +60,7 @@
<header role="banner" class="navbar navbar-fixed-top<?php echo $html->navbarclass ?> moodle-has-zindex">
<nav role="navigation" class="navbar-inner">
<div class="container-fluid">
<a class="brand" href="<?php echo $CFG->wwwroot;?>"><?php echo
format_string($SITE->shortname, true, array('context' => context_course::instance(SITEID)));
?></a>
<?php echo $OUTPUT->navbar_home(); ?>
<?php echo $OUTPUT->navbar_button(); ?>
<?php echo $OUTPUT->user_menu(); ?>
<div class="nav-collapse collapse">
Expand Down
6 changes: 2 additions & 4 deletions theme/clean/layout/secure.php
Expand Up @@ -54,9 +54,7 @@
<header role="banner" class="navbar navbar-fixed-top moodle-has-zindex">
<nav role="navigation" class="navbar-inner">
<div class="container-fluid">
<span class="brand"><?php echo
format_string($SITE->shortname, true, array('context' => context_course::instance(SITEID)));
?></span>
<?php echo $OUTPUT->navbar_home(false); ?>
<?php echo $OUTPUT->navbar_button(); ?>
<div class="nav-collapse collapse">
<ul class="nav pull-right">
Expand Down Expand Up @@ -90,4 +88,4 @@

</div>
</body>
</html>
</html>
4 changes: 2 additions & 2 deletions theme/clean/lib.php
Expand Up @@ -86,13 +86,13 @@ function theme_clean_set_logo($css, $logo) {
* @return bool
*/
function theme_clean_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
if ($context->contextlevel == CONTEXT_SYSTEM and $filearea === 'logo') {
if ($context->contextlevel == CONTEXT_SYSTEM and ($filearea === 'logo' || $filearea === 'smalllogo')) {
$theme = theme_config::load('clean');
// By default, theme files must be cache-able by both browsers and proxies.
if (!array_key_exists('cacheability', $options)) {
$options['cacheability'] = 'public';
}
return $theme->setting_file_serve('logo', $args, $forcedownload, $options);
return $theme->setting_file_serve($filearea, $args, $forcedownload, $options);
} else {
send_file_not_found();
}
Expand Down
16 changes: 16 additions & 0 deletions theme/clean/settings.php
Expand Up @@ -48,6 +48,22 @@
$setting->set_updatedcallback('theme_reset_all_caches');
$settings->add($setting);

// Small logo file setting.
$name = 'theme_clean/smalllogo';
$title = get_string('smalllogo', 'theme_clean');
$description = get_string('smalllogodesc', 'theme_clean');
$setting = new admin_setting_configstoredfile($name, $title, $description, 'smalllogo');
$setting->set_updatedcallback('theme_reset_all_caches');
$settings->add($setting);

// Show site name along with small logo.
$name = 'theme_clean/sitename';
$title = get_string('sitename', 'theme_clean');
$description = get_string('sitenamedesc', 'theme_clean');
$setting = new admin_setting_configcheckbox($name, $title, $description, 1);
$setting->set_updatedcallback('theme_reset_all_caches');
$settings->add($setting);

// Custom CSS file.
$name = 'theme_clean/customcss';
$title = get_string('customcss', 'theme_clean');
Expand Down
31 changes: 31 additions & 0 deletions theme/clean/style/custom.css
Expand Up @@ -16,6 +16,37 @@ div.logo {
float: right;
}

img.small-logo {
float: left;
height: 35px;
margin: 3px 10px 3px 0;
}

.dir-rtl img.small-logo {
float: right;
margin: 3px 0 3px 10px;
}

@media (max-width: 767px) {
.dir-rtl img.small-logo,
img.small-logo {
margin: 3px;
}
}

@media (max-width: 480px) {
.navbar img.small-logo {
max-width: 150px;
}
/* Applying accesshide styles */
.navbar .small-logo-container + .brand {
position: absolute;
left: -10000px;
font-size: 1em;
font-weight: normal;
}
}

/* Custom CSS Settings
-------------------------*/
[[setting:customcss]]
2 changes: 1 addition & 1 deletion theme/clean/version.php
Expand Up @@ -30,7 +30,7 @@

defined('MOODLE_INTERNAL') || die;

$plugin->version = 2015111600;
$plugin->version = 2015111601;
$plugin->requires = 2015111000;
$plugin->component = 'theme_clean';
$plugin->dependencies = array(
Expand Down
3 changes: 3 additions & 0 deletions theme/upgrade.txt
Expand Up @@ -14,6 +14,9 @@ information provided here is intended especially for theme designer.
themes extending bootstrapbase and overriding its layouts can call replace their "a.btn-navbar"
node for a call to this function.
* Themes Clean and More page header logo only displays on front page and login page.
* A new function navbar_home has been added to theme_clean and theme_more to display the navigation bar link
to the site home. Two new settings have been added to control if the link should be a small logo image, text
or both. It defaults to the current behaviour, only a text link.

=== 2.9 ===

Expand Down

0 comments on commit c08b52a

Please sign in to comment.