Skip to content

Commit

Permalink
Merge pull request #42 from moodle-an-hochschulen/issue-34
Browse files Browse the repository at this point in the history
Feature: Configurable favicon, solves #34
  • Loading branch information
lucaboesch authored Jul 7, 2022
2 parents 75bb42d + 57bf9cd commit 56566b5
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions classes/output/core_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}
3 changes: 3 additions & 0 deletions lang/en/theme_boost_union.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Binary file added pix/favicon.ico
Binary file not shown.
15 changes: 15 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
35 changes: 35 additions & 0 deletions tests/behat/theme_boost_union_branding_settings.feature
Original file line number Diff line number Diff line change
@@ -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
Binary file added tests/fixtures/favicon.ico
Binary file not shown.
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 = 2022031707;
$plugin->version = 2022031708;
$plugin->release = 'v4.0-r1';
$plugin->requires = 2022041900;
$plugin->supported = [400, 400];
Expand Down

0 comments on commit 56566b5

Please sign in to comment.