Skip to content

Commit

Permalink
Change of name from 'usermenulogouturl' to 'customlogouturl' and move…
Browse files Browse the repository at this point in the history
… setting from 'Menus' to 'General' in the theme settings to fix the logout URL in the footer being inconsistent with the user menu - #33.
  • Loading branch information
gjb2048 committed Jul 20, 2024
1 parent 7589d54 commit 5fb4d9e
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Version 401.1.5 - TBR
1. Swap over user name and icon in navbar. In line with a design style of other online applications.
2. Add 'activitynavigationenabled' setting to enable / disable activity navigation.
3. Add 'activitynavigationmodulenames' setting to show the activity module names in the navigation or previous / next if unset.
4. Change of name from 'usermenulogouturl' to 'customlogouturl' and move setting from 'Menus' to 'General' in the theme settings
to fix the logout URL in the footer being inconsistent with the user menu - #33.

Version 401.1.4 - 11/03/24
--------------------------
Expand Down
8 changes: 0 additions & 8 deletions classes/module/menus_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,6 @@ public function add_settings(&$settingspages, $toolbox) {
$setting->set_updatedcallback('theme_reset_all_caches'); // Config file uses this setting.
$settingspages['menus'][\theme_foundation\toolbox::SETTINGPAGE]->add($setting);

// Custom user menu url.
$name = 'theme_foundation/usermenulogouturl';
$title = get_string('usermenulogouturl', 'theme_foundation');
$default = '';
$description = get_string('usermenulogouturldesc', 'theme_foundation');
$setting = new \admin_setting_configtext($name, $title, $description, $default, PARAM_URL);
$settingspages['menus'][\theme_foundation\toolbox::SETTINGPAGE]->add($setting);

// Edit switch.
$name = 'theme_foundation/navbareditswitch';
$title = get_string('navbareditswitch', 'theme_foundation');
Expand Down
25 changes: 23 additions & 2 deletions classes/output/core_renderer_toolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,27 @@ public function activity_navigation() {
return $renderer->render($activitynav);
}

/**
* Return the standard string that says whether you are logged in (and switched
* roles/logged in as another user).
* @param bool $withlinks if false, then don't include any links in the HTML produced.
* If not set, the default is the nologinlinks option from the theme config.php file,
* and if that is not set, then links are included.
* @return string HTML fragment.
*/
public function login_info($withlinks = null) {
$loggedinas = parent::login_info($withlinks);

$toolbox = \theme_foundation\toolbox::get_instance();
$customlogouturl = $toolbox->get_setting('customlogouturl');
if (!empty($customlogouturl)) {
// Replace if there.
$loggedinas = str_replace('/login/logout.php', '/theme/foundation/logout.php', $loggedinas);
}

return $loggedinas;
}

/**
* Take a node in the nav tree and make an action menu out of it.
* The links are injected in the action menu.
Expand Down Expand Up @@ -863,8 +884,8 @@ public function user_menu($user = null, $withlinks = null) {

// Logout URL. Only works when Foundation not in $CFG->themedir.
$toolbox = \theme_foundation\toolbox::get_instance();
$usermenulogouturl = $toolbox->get_setting('usermenulogouturl');
if (!empty($usermenulogouturl)) {
$customlogouturl = $toolbox->get_setting('customlogouturl');
if (!empty($customlogouturl)) {
foreach ($opts->navitems as $object) {
if (!empty($object->titleidentifier)) {
$titleidentifier = explode(',', $object->titleidentifier);
Expand Down
8 changes: 8 additions & 0 deletions classes/toolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,14 @@ public function add_settings() {
)
);

// Custom logout url.
$name = 'theme_foundation/customlogouturl';
$title = get_string('customlogouturl', 'theme_foundation');
$default = '';
$description = get_string('customlogouturldesc', 'theme_foundation');
$setting = new \admin_setting_configtext($name, $title, $description, $default, PARAM_URL);
$settingspages['general'][self::SETTINGPAGE]->add($setting);

// Core favicon information.
$name = 'theme_foundation/favicon';
$title = get_string('favicon', 'theme_foundation');
Expand Down
12 changes: 12 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ function xmldb_theme_foundation_upgrade($oldversion = 0) {
upgrade_plugin_savepoint(true, 2021051805, 'theme', 'foundation');
}

if ($oldversion < 2022112606) {
// Change of name from 'usermenulogouturl' to 'customlogouturl'.
$value = get_config('theme_foundation', 'usermenulogouturl');
if (!empty($value)) {
set_config('customlogouturl', $value, 'theme_foundation');
// Prevent replacement in a newer version of the theme!
unset_config('usermenulogouturl', 'theme_foundation');
}

upgrade_plugin_savepoint(true, 2022112606, 'theme', 'foundation');
}

// Automatic 'Purge all caches'....
purge_all_caches();

Expand Down
6 changes: 3 additions & 3 deletions lang/en/theme_foundation.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@
$string['generalheadingsub'] = 'General settings';
$string['generalheadingdesc'] = 'Configure the general settings.';

$string['customlogouturl'] = 'Custom logout URL';
$string['customlogouturldesc'] = 'Set a custom URL to use for the \'Log out\' link. Leave blank for system default. When set, will only work if Foundation is not installed in $CFG->themedir.';

$string['footerantigravityhorizontaloffset'] = 'Screen anti-gravity horizontal offset';
$string['footerantigravityhorizontaloffsetdesc'] = 'Set the horizontal offset of the anti-gravity buttons on the screen (not the navbar) from the default. This can be an positive (move right) or negative (move left) number. The units are pixels. Note: Flip this logic for RTL languages.';

Expand Down Expand Up @@ -298,9 +301,6 @@
$string['navbarstyledark'] = 'Dark';
$string['navbarstylelight'] = 'Light';

$string['usermenulogouturl'] = 'User menu log out URL';
$string['usermenulogouturldesc'] = 'Set a custom URL to use for the \'Log out\' menu item on the user menu. Leave blank for system default. When set, will only work if Foundation is not installed in $CFG->themedir.';

$string['navbareditswitch'] = 'Edit switch';
$string['navbareditswitchdesc'] = 'Have the edit switch on the navbar.';

Expand Down
2 changes: 1 addition & 1 deletion logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

// Logout URL.
$toolbox = \theme_foundation\toolbox::get_instance();
$redirect = $toolbox->get_setting('usermenulogouturl');
$redirect = $toolbox->get_setting('customlogouturl');

if (!$loggedin) {
// User has already logged out.
Expand Down

0 comments on commit 5fb4d9e

Please sign in to comment.