MDL-50661 theme_clean: New small logo setting
authorDavid Monllao <davidm@moodle.com>
Wed, 11 Nov 2015 07:24:18 +0000 (15:24 +0800)
committerDavid Monllao <davidm@moodle.com>
Mon, 30 Nov 2015 01:14:20 +0000 (09:14 +0800)
Introduces new settings to set a small logo in the navbar next
to the site name on pages where the logo is not displayed.

theme/clean/classes/core_renderer.php
theme/clean/lang/en/theme_clean.php
theme/clean/layout/columns1.php
theme/clean/layout/columns2.php
theme/clean/layout/columns3.php
theme/clean/layout/secure.php
theme/clean/lib.php
theme/clean/settings.php
theme/clean/style/custom.css
theme/clean/version.php
theme/upgrade.txt

index 4b27144..74e7b07 100644 (file)
@@ -64,4 +64,58 @@ class theme_clean_core_renderer extends theme_bootstrapbase_core_renderer {
 
         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'));
+    }
 }
index 8904259..f98117d 100644 (file)
@@ -64,3 +64,8 @@ $string['pluginname'] = 'Clean';
 $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.';
index 1258e04..ab4e25a 100644 (file)
@@ -41,9 +41,7 @@ echo $OUTPUT->doctype() ?>
 <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">
index 7f57fcb..8ccbe05 100644 (file)
@@ -50,9 +50,7 @@ echo $OUTPUT->doctype() ?>
 <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">
index 0b03794..03200e8 100644 (file)
@@ -60,9 +60,7 @@ echo $OUTPUT->doctype() ?>
 <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">
index 5113ae7..857c002 100644 (file)
@@ -54,9 +54,7 @@ echo $OUTPUT->doctype() ?>
 <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">
@@ -90,4 +88,4 @@ echo $OUTPUT->doctype() ?>
 
 </div>
 </body>
-</html>
\ No newline at end of file
+</html>
index 4a46bba..889c9ae 100644 (file)
@@ -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();
     }
index cf0df83..0f265db 100644 (file)
@@ -48,6 +48,22 @@ if ($ADMIN->fulltree) {
     $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');
index bb4cc68..b8d37a0 100644 (file)
@@ -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]]
index 01427e4..4782380 100644 (file)
@@ -30,7 +30,7 @@
 
 defined('MOODLE_INTERNAL') || die;
 
-$plugin->version   = 2015111600;
+$plugin->version   = 2015111601;
 $plugin->requires  = 2015111000;
 $plugin->component = 'theme_clean';
 $plugin->dependencies = array(
index bb052c5..1264298 100644 (file)
@@ -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 ===