Skip to content

Commit

Permalink
Finishing the task to build a theme extension in moodle-an-hochschule…
Browse files Browse the repository at this point in the history
  • Loading branch information
DocDanou committed May 17, 2024
1 parent 33faca2 commit 37be702
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 25 deletions.
8 changes: 4 additions & 4 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,7 @@ function theme_boost_union_get_pre_scss($theme) {
if (get_config('theme_boost_union', 'blockdrawerwidth')) {
$scss .= '$drawer-right-width: '.get_config('theme_boost_union', 'blockdrawerwidth').";\n";
}
// Set variables which are read in settings by the logo maxwidth values. #544
if (get_config('theme_boost_union', 'maxlogowidth')) {
$scss .= ".navbar-brand img.logo{max-width:".get_config('theme_boost_union', 'maxlogowidth').";height:auto;}\n";
}

// Set custom Boost Union SCSS variable: The block region outside left width.
$blockregionoutsideleftwidth = get_config('theme_boost_union', 'blockregionoutsideleftwidth');
// If the setting is not set.
Expand Down Expand Up @@ -331,6 +328,9 @@ function theme_boost_union_get_extra_scss($theme) {
// Setting: Activity icon purpose.
$content .= theme_boost_union_get_scss_for_activity_icon_purpose($theme);

// Setting: Navbar and icon styles.
$content .= theme_boost_union_get_scss_navbar($theme);

// Setting: Mark external links.
$content .= theme_boost_union_get_scss_to_mark_external_links($theme);

Expand Down
20 changes: 20 additions & 0 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,26 @@ function theme_boost_union_get_scss_courseoverview_block($theme) {
return $scss;
}


/**
* Returns the SCSS code to be used in the navbar. The first usage is a logo icon that is possibly too broad and needs
* reduced to fit the navbar. See theme_boost_union_maxlogowidth for further details
*
* @param theme_config $theme The theme config object.
* @return string
*/
function theme_boost_union_get_scss_navbar($theme) {
// Initialize SCSS snippet.
$scss = '';

// Set variables which are read in settings by the logo maxwidth values.
if (get_config('theme_boost_union', 'maxlogowidth')) {
$scss .= ".navbar-brand img.logo{max-width:".get_config('theme_boost_union', 'maxlogowidth').";height:auto;}\n";
}

return $scss;
}

/**
* Helper function which returns an array of login methods on the login page.
*
Expand Down
11 changes: 6 additions & 5 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@
// (with 3 or 4 digits) or a viewport width number (from 0 to 100).
$widthregex = '/^((\d{1,2}|100)%)|((\d{1,2}|100)vw)|(\d{3,4}px)$/';

// Prepare regular expression for checking if the value is a percent number (from 0% to 100%) or a pixel number
// (with 2 or 3 digits) or a viewport width number (from 0 to 100). Additionally the field can be left blank.
$smallsizeoremptyregex = '/^((\d{1,2}|100)%)|((\d{1,2}|100)vw)|(\d{2,3}px)|(^(?!.*\S))$/';

// Create Look settings page with tabs
// (and allow users with the theme/boost_union:configure capability to access it).
$page = new theme_boost_admin_settingspage_tabs('theme_boost_union_look',
Expand Down Expand Up @@ -270,15 +274,12 @@
$setting->set_updatedcallback('theme_reset_all_caches');
$tab->add($setting);

// Setting: add extra SCSS if logo icon is too broad / wrong aspect ratio. See Issue-544.
// Setting: add extra SCSS if logo icon is too broad / wrong aspect ratio.
$name = 'theme_boost_union/maxlogowidth';
$title = get_string('maxlogowidth', 'theme_boost_union', null, true);
$description = get_string('maxlogowidth_desc', 'theme_boost_union', null, true);
$default = '';
// Prepare regular expression for checking if the value is a percent number (from 0% to 100%) or a pixel number
// (with 2 or 3 digits) or a viewport width number (from 0 to 100). Additionally the field can be left blank.
$maxlogowidthregex = '/^((\d{1,2}|100)%)|((\d{1,2}|100)vw)|(\d{2,3}px)|(^(?!.*\S))$/';
$setting = new admin_setting_configtext($name, $title, $description, $default, $maxlogowidthregex, 6);
$setting = new admin_setting_configtext($name, $title, $description, $default, $smallsizeoremptyregex, 6);
$setting->set_updatedcallback('theme_reset_all_caches');
$tab->add($setting);

Expand Down
26 changes: 11 additions & 15 deletions tests/behat/theme_boost_union_looksettings_sitebranding.feature
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,22 @@ Feature: Configuring the theme_boost_union plugin for the "Site branding" tab on
And I am on site homepage
Then ".navbar .logo" "css_element" should not exist

Scenario: Setting: Logo max-width - limit logo width readout from theme_config entry
Scenario Outline: Setting: Logo max-width - limit logo width readout from theme_config entry
Given the following config values are set as admin:
| config | value | plugin |
| maxlogowidth | 100px | theme_boost_union |
| config | value | plugin |
| maxlogowidth | <css-rule> | theme_boost_union |
And the theme cache is purged and the theme is reloaded
When I log in as "student1"
And I am on site homepage
Then DOM element ".navbar-brand img.logo" should have computed style "max-width" "100px"
And DOM element ".navbar-brand img.logo" should have computed style "height" "auto"
Then DOM element ".navbar-brand img.logo" <should-have> computed style "<css-name>" "<css-rule>"
And DOM element ".navbar-brand img.logo" should have computed style "height" "<css-height>"

Scenario: Setting: Logo max-width - limit logo through admin settings - manual add the entry
When I log in as "admin"
And I navigate to "Appearance > Boost Union > Look" in site administration
And I click on "Site branding" "link" in the "#adminsettings .nav-tabs" "css_element"
And I set the field "Maximal width of logo" to "200px"
And I press "Save changes"
And the theme cache is purged and the theme is reloaded
And I am on site homepage
Then DOM element ".navbar-brand img.logo" should have computed style "max-width" "200px"
And DOM element ".navbar-brand img.logo" should have computed style "height" "auto"
Examples:
| css-name | css-rule | css-height | should-have |
| max-width | 100px | auto | should have |
| max-width | 10vw | auto | should have |
| max-width | 13% | auto | should have |
| max-width | | 100% | should not have |

Scenario: Setting: Logo max-width - limit logo through admin settings - check regex to limit entry (countercheck)
When I log in as "admin"
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'theme_boost_union';
$plugin->version = 2024051400;
$plugin->version = 2023102039;
$plugin->release = 'v4.3-r12';
$plugin->requires = 2023100900;
$plugin->supported = [403, 403];
Expand Down

0 comments on commit 37be702

Please sign in to comment.