diff --git a/CHANGES.md b/CHANGES.md index bc602c2ce86..90e725979fd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Changes ### Unreleased +* 2022-07-05 - Feature: Configurable favicon, solves #34 * 2022-07-05 - Feature: Allow non-admins to edit theme settings, solves #28 * 2022-07-05 - Feature: Back to top button, solves #7 * 2022-07-05 - Adopt changes in Boost core for MDL-74634 diff --git a/README.md b/README.md index 774e4a1b71a..a533826ddd3 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,12 @@ With this setting a back to top button will appear in the bottom right corner of In this tab there are the following settings: +#### Favicon + +##### Favicon + +Here, you can upload a custom image (.ico or .png format) that the browser will show as the favicon of your Moodle website. If no custom favicon is uploaded, a standard Moodle favicon will be used. + #### Background images ##### Background image diff --git a/classes/output/core_renderer.php b/classes/output/core_renderer.php index 39d1abfb6ed..0abb65bf3a0 100644 --- a/classes/output/core_renderer.php +++ b/classes/output/core_renderer.php @@ -33,4 +33,19 @@ */ class core_renderer extends \theme_boost\output\core_renderer { + /** + * Returns the moodle_url for the favicon. + * + * This renderer function is copied and modified from /lib/outputrenderers.php + * + * @since Moodle 2.5.1 2.6 + * @return moodle_url The moodle_url for the favicon + */ + public function favicon() { + if (!empty($this->page->theme->settings->favicon)) { + return $this->page->theme->setting_file_url('favicon', 'favicon'); + } else { + return $this->image_url('favicon', 'theme'); + } + } } diff --git a/lang/en/theme_boost_union.php b/lang/en/theme_boost_union.php index c173fb143fc..9ef0ba74c11 100644 --- a/lang/en/theme_boost_union.php +++ b/lang/en/theme_boost_union.php @@ -44,6 +44,9 @@ // Settings: Branding tab. $string['brandingtab'] = 'Branding'; +$string['faviconheading'] = 'Favicon'; +$string['faviconsetting'] = 'Favicon'; +$string['faviconsetting_desc'] = 'Here, you can upload a custom image (.ico or .png format) that the browser will show as the favicon of your Moodle website. If no custom favicon is uploaded, a standard Moodle favicon will be used.'; $string['backgroundimagesheading'] = 'Background images'; $string['brandcolorsheading'] = 'Brand colors'; diff --git a/lib.php b/lib.php index a46a1ba83d4..aed682f37f6 100644 --- a/lib.php +++ b/lib.php @@ -146,7 +146,7 @@ function theme_boost_union_get_precompiled_css() { */ function theme_boost_union_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) { if ($context->contextlevel == CONTEXT_SYSTEM && ($filearea === 'logo' || $filearea === 'backgroundimage' || - $filearea === 'loginbackgroundimage')) { + $filearea === 'loginbackgroundimage' || $filearea === 'favicon')) { $theme = theme_config::load('boost_union'); // By default, theme files must be cache-able by both browsers and proxies. if (!array_key_exists('cacheability', $options)) { diff --git a/pix/favicon.ico b/pix/favicon.ico new file mode 100644 index 00000000000..eea02482c37 Binary files /dev/null and b/pix/favicon.ico differ diff --git a/settings.php b/settings.php index f0647bebcc1..f525d90aa94 100644 --- a/settings.php +++ b/settings.php @@ -137,6 +137,21 @@ // Create branding tab. $page = new admin_settingpage('theme_boost_union_branding', get_string('brandingtab', 'theme_boost_union', null, true)); + // Create favicon heading. + $name = 'theme_boost_union/faviconheading'; + $title = get_string('faviconheading', 'theme_boost_union', null, true); + $setting = new admin_setting_heading($name, $title, null); + $page->add($setting); + + // Setting: Favicon. + $name = 'theme_boost_union/favicon'; + $title = get_string('faviconsetting', 'theme_boost_union', null, true); + $description = get_string('faviconsetting_desc', 'theme_boost_union', null, true); + $setting = new admin_setting_configstoredfile($name, $title, $description, 'favicon', 0, + array('maxfiles' => 1, 'accepted_types' => array('.ico', '.png'))); + $setting->set_updatedcallback('theme_reset_all_caches'); + $page->add($setting); + // Create background images heading. $name = 'theme_boost_union/backgroundimagesheading'; $title = get_string('backgroundimagesheading', 'theme_boost_union', null, true); diff --git a/tests/behat/theme_boost_union_branding_settings.feature b/tests/behat/theme_boost_union_branding_settings.feature new file mode 100644 index 00000000000..f755f087842 --- /dev/null +++ b/tests/behat/theme_boost_union_branding_settings.feature @@ -0,0 +1,35 @@ +@theme @theme_boost_union @theme_boost_union_branding_settings +Feature: Configuring the theme_boost_union plugin for the "Branding" tab + In order to use the features + As admin + I need to be able to configure the theme Boost Union plugin + + Background: + Given the following "users" exist: + | username | + | student1 | + | teacher1 | + And the following "courses" exist: + | fullname | shortname | + | Course 1 | C1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + + @javascript @_file_upload + Scenario: Upload a custom favicon + When I log in as "admin" + And I navigate to "Appearance > Boost Union" in site administration + And I click on "Branding" "link" + And I upload "theme/boost_union/tests/fixtures/favicon.ico" file to "Favicon" filemanager + And I press "Save changes" + # We can't check the uploaded favicon visually, but we can verify that the site's favicon is not shipped by pluginfile.php (for uploaded files) and not by theme/image.php (for image files from disk) anymore. + Then "//head//link[contains(@rel, 'shortcut')][contains(@href, 'pluginfile.php/1/theme_boost_union/favicon')][contains(@href, 'favicon.ico')]" "xpath_element" should exist + And "//head//link[contains(@rel, 'shortcut')][contains(@href, 'theme/image.php/boost_union/theme')][contains(@href, 'favicon')]" "xpath_element" should not exist + + @javascript @_file_upload + Scenario: Do not upload a custom favicon (countercheck) + When I log in as "admin" + Then "//head//link[contains(@rel, 'shortcut')][contains(@href, 'theme/image.php/boost_union/theme')][contains(@href, 'favicon')]" "xpath_element" should exist + And "//head//link[contains(@rel, 'shortcut')][contains(@href, 'pluginfile.php/1/theme_boost_union/favicon')][contains(@href, 'favicon.ico')]" "xpath_element" should not exist diff --git a/tests/fixtures/favicon.ico b/tests/fixtures/favicon.ico new file mode 100644 index 00000000000..eea02482c37 Binary files /dev/null and b/tests/fixtures/favicon.ico differ diff --git a/version.php b/version.php index dcb4187fa01..aa315efd8b0 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'theme_boost_union'; -$plugin->version = 2022031707; +$plugin->version = 2022031708; $plugin->release = 'v4.0-r1'; $plugin->requires = 2022041900; $plugin->supported = [400, 400];