From 04e4ed6f7445da95c8c0f8455992179fd7c92c42 Mon Sep 17 00:00:00 2001 From: Alexander Bias Date: Thu, 7 Jul 2022 10:11:53 +0200 Subject: [PATCH] Feature: Make the course content column width configurable, helps to resolve #18. With this patch, admins can override Moodle's default content width without manual SCSS modifications. --- CHANGES.md | 1 + README.md | 6 ++++++ lang/en/theme_boost_union.php | 3 +++ lib.php | 6 ++++++ settings.php | 17 +++++++++++++++++ .../theme_boost_union_page_settings.feature | 3 +++ version.php | 2 +- 7 files changed, 37 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index cc6c468cecb..313ab465049 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Changes ### Unreleased +* 2022-07-07 - Feature: Make the course content column width configurable, helps to resolve #18. * 2022-07-06 - Feature: Built-in imprint, solves #32 * 2022-07-05 - Feature: Configurable favicon, solves #34 * 2022-07-05 - Feature: Allow non-admins to edit theme settings, solves #28 diff --git a/README.md b/README.md index 89ab1d91f28..a292222e153 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,12 @@ This setting is already available in the Moodle core theme Boost. For more infor In this tab there are the following settings: +#### Layout + +##### Course content max width + +With this setting, you can override Moodle's default content width without manual SCSS modifications. + #### Navigation ##### Back to top button diff --git a/lang/en/theme_boost_union.php b/lang/en/theme_boost_union.php index 49712921082..f5e3456bcd9 100644 --- a/lang/en/theme_boost_union.php +++ b/lang/en/theme_boost_union.php @@ -37,6 +37,9 @@ // Settings: Page tab. $string['pagetab'] = 'Page'; +$string['layoutheading'] = 'Layout'; +$string['coursecontentmaxwidthsetting'] = 'Course content max width'; +$string['coursecontentmaxwidthsetting_desc'] = 'With this setting, you can override Moodle\'s default content width without manual SCSS modifications. By default, Moodle uses a course content max width of 830px. You can enter other pixel-based values like 1200px, but you can also enter a percentage-based value like 100%.'; $string['navigationheading'] = 'Navigation'; $string['backtotop'] = 'Back to top'; $string['backtotopbuttonsetting'] = 'Back to top button'; diff --git a/lib.php b/lib.php index 8478e1ab5f3..2c9c350dc45 100644 --- a/lib.php +++ b/lib.php @@ -88,6 +88,12 @@ function theme_boost_union_get_pre_scss($theme) { }, (array) $targets); } + // Overwrite Boost core SCSS variables which need units and thus couldn't be added to $configurable above. + // Set variables which are influenced by the coursecontentmaxwidth setting. + if (isset($theme->settings->coursecontentmaxwidth)) { + $scss .= '$course-content-maxwidth: '.$theme->settings->coursecontentmaxwidth.";\n"; + } + // Prepend pre-scss. if (!empty($theme->settings->scsspre)) { $scss .= $theme->settings->scsspre; diff --git a/settings.php b/settings.php index 1aa25121ecc..7925bd20fb7 100644 --- a/settings.php +++ b/settings.php @@ -117,6 +117,23 @@ // Create page tab. $page = new admin_settingpage('theme_boost_union_page', get_string('pagetab', 'theme_boost_union', null, true)); + // Create layout heading. + $name = 'theme_boost_union/layoutheading'; + $title = get_string('layoutheading', 'theme_boost_union', null, true); + $setting = new admin_setting_heading($name, $title, null); + $page->add($setting); + + // Setting: Course content max width. + $name = 'theme_boost_union/coursecontentmaxwidth'; + $title = get_string('coursecontentmaxwidthsetting', 'theme_boost_union', null, true); + $description = get_string('coursecontentmaxwidthsetting_desc', 'theme_boost_union', null, true); + $default = '830px'; + // Regular expression for checking if the value is a percent number (from 0% to 100%) or a pixel number (with 3 or 4 digits). + $regex = '/^((\d{1,2}|100)%)|(\d{3,4}px)$/'; + $setting = new admin_setting_configtext($name, $title, $description, $default, $regex, 7); + $setting->set_updatedcallback('theme_reset_all_caches'); + $page->add($setting); + // Create navigation heading. $name = 'theme_boost_union/navigationheading'; $title = get_string('navigationheading', 'theme_boost_union', null, true); diff --git a/tests/behat/theme_boost_union_page_settings.feature b/tests/behat/theme_boost_union_page_settings.feature index b4e8b6cf907..7547d452f96 100644 --- a/tests/behat/theme_boost_union_page_settings.feature +++ b/tests/behat/theme_boost_union_page_settings.feature @@ -17,6 +17,9 @@ Feature: Configuring the theme_boost_union plugin for the "Page" tab | teacher1 | C1 | editingteacher | | student1 | C1 | student | + # Unfortunately, this can't be tested with Behat yet + # Scenario: Overwrite the course content max width setting + @javascript Scenario: Enable "Back to top button" Given the following config values are set as admin: diff --git a/version.php b/version.php index 897c5bb6087..7354c6ff704 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'theme_boost_union'; -$plugin->version = 2022031709; +$plugin->version = 2022031710; $plugin->release = 'v4.0-r1'; $plugin->requires = 2022041900; $plugin->supported = [400, 400];