MDL-69371 theme_boost: allow configuring a login background image

This commit is contained in:
Bas Brands 2021-10-13 09:35:58 +02:00
parent 47bbfe0f4f
commit 7c2e6d07af
6 changed files with 40 additions and 2 deletions

View File

@ -35,6 +35,8 @@ $string['choosereadme'] = 'Boost is a modern highly-customisable theme. This the
$string['currentinparentheses'] = '(current)';
$string['configtitle'] = 'Boost';
$string['generalsettings'] = 'General settings';
$string['loginbackgroundimage'] = 'Background image for the login page';
$string['loginbackgroundimage_desc'] = 'The image to display as a background for the login page.';
$string['nobootswatch'] = 'None';
$string['pluginname'] = 'Boost';
$string['presetfiles'] = 'Additional theme preset files';

View File

@ -54,6 +54,14 @@ function theme_boost_get_extra_scss($theme) {
$content .= ' }';
}
// Sets the login background image.
$loginbackgroundimageurl = $theme->setting_file_url('loginbackgroundimage', 'loginbackgroundimage');
if (!empty($loginbackgroundimageurl)) {
$content .= 'body.pagelayout-login #page { ';
$content .= "background-image: url('$loginbackgroundimageurl'); background-size: cover;";
$content .= ' }';
}
// Always return the background image with the scss when we have it.
return !empty($theme->settings->scss) ? $theme->settings->scss . ' ' . $content : $content;
}
@ -71,7 +79,8 @@ function theme_boost_get_extra_scss($theme) {
* @return bool
*/
function theme_boost_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
if ($context->contextlevel == CONTEXT_SYSTEM && ($filearea === 'logo' || $filearea === 'backgroundimage')) {
if ($context->contextlevel == CONTEXT_SYSTEM && ($filearea === 'logo' || $filearea === 'backgroundimage' ||
$filearea === 'loginbackgroundimage')) {
$theme = theme_config::load('boost');
// By default, theme files must be cache-able by both browsers and proxies.
if (!array_key_exists('cacheability', $options)) {

View File

@ -65,6 +65,14 @@ if ($ADMIN->fulltree) {
$setting->set_updatedcallback('theme_reset_all_caches');
$page->add($setting);
// Login Background image setting.
$name = 'theme_boost/loginbackgroundimage';
$title = get_string('loginbackgroundimage', 'theme_boost');
$description = get_string('loginbackgroundimage_desc', 'theme_boost');
$setting = new admin_setting_configstoredfile($name, $title, $description, 'loginbackgroundimage');
$setting->set_updatedcallback('theme_reset_all_caches');
$page->add($setting);
// Variable $body-color.
// We use an empty default value because the default colour should come from the preset.
$name = 'theme_boost/brandcolor';

View File

@ -42,7 +42,11 @@
<div id="page-content" class="row">
<div id="region-main-box" class="col-12">
<section id="region-main" class="col-12 h-100" aria-label="{{#str}}content{{/str}}">
<div class="login-wrapper">
<div class="login-container">
{{{ output.main_content }}}
</div>
</div>
</section>
</div>
</div>

View File

@ -101,6 +101,14 @@ function theme_classic_get_extra_scss($theme) {
'/theme/classic/scss/classic/body-background.scss');
}
// Sets the login background image.
$loginbackgroundimageurl = $theme->setting_file_url('loginbackgroundimage', 'loginbackgroundimage');
if (!empty($loginbackgroundimageurl)) {
$content .= 'body.pagelayout-login #page { ';
$content .= "background-image: url('$loginbackgroundimageurl'); background-size: cover;";
$content .= ' }';
}
if (!empty($theme->settings->navbardark)) {
$content .= file_get_contents($CFG->dirroot .
'/theme/classic/scss/classic/navbar-dark.scss');
@ -137,7 +145,7 @@ function theme_classic_get_precompiled_css() {
* @return bool
*/
function theme_classic_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
if ($context->contextlevel == CONTEXT_SYSTEM && ($filearea === 'backgroundimage')) {
if ($context->contextlevel == CONTEXT_SYSTEM && ($filearea === 'backgroundimage' || $filearea === 'loginbackgroundimage')) {
$theme = theme_config::load('classic');
// By default, theme files must be cache-able by both browsers and proxies.
if (!array_key_exists('cacheability', $options)) {

View File

@ -75,6 +75,13 @@ if ($ADMIN->fulltree) {
$setting->set_updatedcallback('theme_reset_all_caches');
$page->add($setting);
$name = 'theme_classic/loginbackgroundimage';
$title = get_string('loginbackgroundimage', 'theme_boost');
$description = get_string('loginbackgroundimage_desc', 'theme_boost');
$setting = new admin_setting_configstoredfile($name, $title, $description, 'loginbackgroundimage');
$setting->set_updatedcallback('theme_reset_all_caches');
$page->add($setting);
// Variable $body-color.
// We use an empty default value because the default colour should come from the preset.
$name = 'theme_classic/brandcolor';