Skip to content

Commit

Permalink
MDL-72867 Navigations: User menu improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
HuongNV13 committed Dec 15, 2021
1 parent 222c8cc commit 8c33689
Show file tree
Hide file tree
Showing 22 changed files with 164 additions and 147 deletions.
8 changes: 4 additions & 4 deletions admin/settings/appearance.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
'customusermenuitems',
new lang_string('customusermenuitems', 'admin'),
new lang_string('configcustomusermenuitems', 'admin'),
'grades,grades|/grade/report/mygrades.php|t/grades
calendar,core_calendar|/calendar/view.php?view=month|i/calendar
messages,message|/message/index.php|t/message
preferences,moodle|/user/preferences.php|t/preferences',
'profile,moodle|/user/profile.php
grades,grades|/grade/report/mygrades.php
calendar,core_calendar|/calendar/view.php?view=month
privatefiles,moodle|/user/files.php',
PARAM_RAW,
'50',
'10'
Expand Down
15 changes: 8 additions & 7 deletions admin/tool/admin_presets/db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ function xmldb_tool_admin_presets_install() {

helper::add_item($presetid, 'showdataretentionsummary', '0', 'tool_dataprivacy');
helper::add_item($presetid, 'forum_maxattachments', '3');
helper::add_item($presetid, 'customusermenuitems', 'grades,grades|/grade/report/mygrades.php|t/grades
calendar,core_calendar|/calendar/view.php?view=month|i/calendar
preferences,moodle|/user/preferences.php|t/preferences');
helper::add_item($presetid, 'customusermenuitems', 'profile,moodle|/user/profile.php
grades,grades|/grade/report/mygrades.php
calendar,core_calendar|/calendar/view.php?view=month
privatefiles,moodle|/user/files.php');

// Modules: Hide chat, database, external tool (lti), IMS content package (imscp), lesson, SCORM, survey, wiki, workshop.
helper::add_plugin($presetid, 'mod', 'chat', false);
Expand Down Expand Up @@ -160,10 +161,10 @@ function xmldb_tool_admin_presets_install() {
helper::add_item($presetid, 'showdataretentionsummary', '1', 'tool_dataprivacy');
helper::add_item($presetid, 'forum_maxattachments', '9');
// In that case, the indentation coding style can't follow the rules to guarantee the setting value is created properly.
helper::add_item($presetid, 'customusermenuitems', 'grades,grades|/grade/report/mygrades.php|t/grades
calendar,core_calendar|/calendar/view.php?view=month|i/calendar
messages,message|/message/index.php|t/message
preferences,moodle|/user/preferences.php|t/preferences'
helper::add_item($presetid, 'customusermenuitems', 'profile,moodle|/user/profile.php
grades,grades|/grade/report/mygrades.php
calendar,core_calendar|/calendar/view.php?view=month
privatefiles,moodle|/user/files.php'
);

// Modules: Enable chat, database, external tool (lti), IMS content package (imscp), lesson, SCORM, survey, wiki, workshop.
Expand Down
6 changes: 3 additions & 3 deletions admin/tool/usertours/tests/behat/tour_navigation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Feature: Steps can be navigated within a tour
| targettype | Block | Title | Content |
| Block | Calendar | Calendar events | This is the calendar block |
And I change window size to "large"
And I follow "Dashboard" in the user menu
And I follow "Dashboard"
And I wait until the page is ready
And I should see "This is the calendar block"
When I click on ".block_calendar_month .calendar-controls .next" "css_element"
Expand All @@ -35,7 +35,7 @@ Feature: Steps can be navigated within a tour
| targettype | Block | Title | Content |
| Block | Calendar | Calendar events | This is the calendar block |
And I change window size to "large"
And I follow "Dashboard" in the user menu
And I follow "Dashboard"
And I wait until the page is ready
And I should see "This is the calendar block"
Then I should see "Got it"
Expand Down Expand Up @@ -76,7 +76,7 @@ Feature: Steps can be navigated within a tour
| targettype | Block | Title | Content |
| Block | Calendar | Calendar events | This is the calendar block |
And I change window size to "large"
And I follow "Dashboard" in the user menu
And I follow "Dashboard"
And I wait until the page is ready
And I should see "This is the calendar block"
Then I should see "CustomText"
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Feature: The recently accessed courses block allows users to easily access their
And I should not see "Course 2" in the "Recently accessed courses" "block"
When I am on "Course 1" course homepage
And I am on "Course 2" course homepage
And I follow "Dashboard" in the user menu
And I follow "Dashboard"
And I change window size to "large"
Then I should see "Course 1" in the "Recently accessed courses" "block"
And I should see "Course 2" in the "Recently accessed courses" "block"
Expand All @@ -53,7 +53,7 @@ Feature: The recently accessed courses block allows users to easily access their
And I log in as "student1"
And I am on "Course 1" course homepage
And I am on "Course 4" course homepage
And I follow "Dashboard" in the user menu
And I follow "Dashboard"
And I should see "Category 1" in the "Recently accessed courses" "block"
And I should see "Category A" in the "Recently accessed courses" "block"

Expand All @@ -63,7 +63,7 @@ Feature: The recently accessed courses block allows users to easily access their
And I log in as "student1"
And I am on "Course 1" course homepage
And I am on "Course 4" course homepage
And I follow "Dashboard" in the user menu
And I follow "Dashboard"
And I should not see "Category 1" in the "Recently accessed courses" "block"
And I should not see "Category A" in the "Recently accessed courses" "block"

Expand All @@ -73,7 +73,7 @@ Feature: The recently accessed courses block allows users to easily access their
And I log in as "student1"
And I am on "Course 1" course homepage
And I am on "Course 4" course homepage
And I follow "Dashboard" in the user menu
And I follow "Dashboard"
And I should see "C1" in the "Recently accessed courses" "block"
And I should see "C4" in the "Recently accessed courses" "block"

Expand All @@ -83,6 +83,6 @@ Feature: The recently accessed courses block allows users to easily access their
And I log in as "student1"
And I am on "Course 1" course homepage
And I am on "Course 4" course homepage
And I follow "Dashboard" in the user menu
And I follow "Dashboard"
And I should not see "C1" in the "Recently accessed courses" "block"
And I should not see "C4" in the "Recently accessed courses" "block"
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ Feature: The recently accessed items block allows users to easily access their m
Scenario: User has accessed some items
Given I change window size to "large"
When I am on the "Test forum name" "forum activity" page
And I follow "Dashboard" in the user menu
And I follow "Dashboard"
Then I should see "Test forum name" in the "Recently accessed items" "block"
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Feature: Adding and configuring YouTube block
Scenario: Category options are not available (except default) in the block settings if the YouTube API key is not set.
Given the following config values are set as admin:
| apikey | | block_tag_youtube |
And I follow "Dashboard" in the user menu
And I follow "Dashboard"
And I turn editing mode on
# TODO MDL-57120 site "Tags" link not accessible without navigation block.
And I add the "Navigation" block if not present
Expand All @@ -33,7 +33,7 @@ Feature: Adding and configuring YouTube block
Scenario: Category options are not available (except default) in the block settings when invalid YouTube API key is set.
Given the following config values are set as admin:
| apikey | invalidapikeyvalue | block_tag_youtube |
And I follow "Dashboard" in the user menu
And I follow "Dashboard"
And I turn editing mode on
And I add the "Navigation" block if not present
And I click on "Site pages" "list_item" in the "Navigation" "block"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Feature: H5P file upload to content bank for admins
Scenario: Admins can upload and deployed content types when libraries are not installed
Given I navigate to "H5P > Manage H5P content types" in site administration
And I should not see "Fill in the Blanks"
And I follow "Dashboard" in the user menu
And I follow "Dashboard"
And I expand "Site pages" node
And I click on "Content bank" "link"
And I should not see "filltheblanks.h5p"
Expand Down
2 changes: 1 addition & 1 deletion contentbank/tests/behat/delete_content.feature
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Feature: Delete H5P file from the content bank
And I should see "Delete"

Scenario: The number of times a content is used is displayed before removing it
Given I follow "Dashboard" in the user menu
Given I follow "Dashboard"
And I follow "Manage private files..."
And I click on "Add..." "button"
And I select "Content bank" repository in file picker
Expand Down
4 changes: 2 additions & 2 deletions contentbank/tests/behat/edit_content.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Feature: Content bank use editor feature
Then the "[data-action=Add-content]" "css_element" should be disabled

Scenario: Users can see the Add button if there is content type available for creation
Given I follow "Dashboard" in the user menu
Given I follow "Dashboard"
And I follow "Manage private files..."
And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "Files" filemanager
And I click on "Save changes" "button"
Expand All @@ -39,7 +39,7 @@ Feature: Content bank use editor feature
And I should see "Fill in the Blanks"

Scenario: Users can edit content if they have the required permission
Given I follow "Dashboard" in the user menu
Given I follow "Dashboard"
And I follow "Manage private files..."
And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "Files" filemanager
And I click on "Save changes" "button"
Expand Down
2 changes: 1 addition & 1 deletion contentbank/tests/behat/events.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Feature: Confirm content bank events are triggered
And the following "contentbank content" exist:
| contextlevel | reference | contenttype | user | contentname | filepath |
| Course | C1 | contenttype_h5p | admin | Existing | /h5p/tests/fixtures/filltheblanks.h5p |
And I follow "Dashboard" in the user menu
And I follow "Dashboard"
And I follow "Manage private files..."
And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "Files" filemanager
And I click on "Save changes" "button"
Expand Down
2 changes: 1 addition & 1 deletion contentbank/tests/behat/view_preferences.feature
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Feature: Store the content bank view preference
And I should not see "Last modified"

Scenario: Display the number of times a content is used in file details view
Given I follow "Dashboard" in the user menu
Given I follow "Dashboard"
And I follow "Manage private files..."
And I click on "Add..." "button"
And I select "Content bank" repository in file picker
Expand Down
2 changes: 1 addition & 1 deletion lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
-Preguntas más frecuentes|https://someurl.xyz/pmf||es
Mobile app|https://someurl.xyz/app|Download our app
</pre>';
$string['configcustomusermenuitems'] = 'You can configure the contents of the user menu (with the exception of the log out link, which is automatically added). Each line is separated by pipe characters and consists of 1) a string in "langstringname, componentname" form or as plain text, 2) a URL, and 3) an icon either as a pix icon (in the folder pix with the structure [subfoldername]/[iconname], e.g. i/publish) or as a URL. Dividers can be used by adding a line of one or more # characters where desired.';
$string['configcustomusermenuitems'] = 'You can configure the contents of the user menu (with the exception of the log out link, which is automatically added). Each line is separated by pipe characters and consists of 1) a string in "langstringname, componentname" form or as plain text, and 2) a URL. Dividers can be used by adding a line of one or more # characters where desired.';
$string['configdbsessions'] = 'If enabled, this setting will use the database to store information about current sessions. Note that changing this setting now will log out all current users (including you). If you are using MySQL please make sure that \'max_allowed_packet\' in my.cnf (or my.ini) is at least 4M. Other session drivers can be configured directly in config.php, see config-dist.php for more information. This option disappears if you specify session driver in config.php file.';
$string['configdebug'] = 'If you turn this on, then PHP\'s error_reporting will be increased so that more warnings are printed. This is only useful for developers.';
$string['configdebugdisplay'] = 'Set to on, the error reporting will go to the HTML page. This is practical, but breaks XHTML, JS, cookies and HTTP headers in general. Set to off, it will send the output to your server logs, allowing better debugging. The PHP setting error_log controls which log this goes to.';
Expand Down
4 changes: 1 addition & 3 deletions lib/classes/navigation/output/primary.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ public function get_user_menu(renderer_base $output): array {
'itemtype' => 'submenu-link',
'submenuid' => $langsubmenuid,
'title' => get_string('language'),
'pixicon' => 'i/language',
'divider' => false,
'submenulink' => true,
];
Expand All @@ -226,8 +225,7 @@ public function get_user_menu(renderer_base $output): array {
}
}

// Add dividers after the first item and before the last item.
$modifiedarray[0]->divider = true;
// Add divider before the last item.
$modifiedarray[count($modifiedarray) - 2]->divider = true;
$usermenudata['items'] = $modifiedarray;
$usermenudata['submenus'] = array_values($submenusdata);
Expand Down
51 changes: 51 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3189,5 +3189,56 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2021120100.01);
}

if ($oldversion < 2021121000.01) {
// Get current configuration data.
$currentcustomusermenuitems = str_replace(["\r\n", "\r"], "\n", $CFG->customusermenuitems);

// The old default customusermenuitems config for 3.11 and below.
$oldcustomusermenuitems = 'grades,grades|/grade/report/mygrades.php|t/grades
calendar,core_calendar|/calendar/view.php?view=month|i/calendar
messages,message|/message/index.php|t/message
preferences,moodle|/user/preferences.php|t/preferences';

// Check if the current customusermenuitems config matches the old customusermenuitems config.
$samecustomusermenuitems = $currentcustomusermenuitems == $oldcustomusermenuitems;
if ($samecustomusermenuitems) {
// If the site is still using the old defaults, upgrade to the new default.
$newcustomusermenuitems = 'profile,moodle|/user/profile.php
grades,grades|/grade/report/mygrades.php
calendar,core_calendar|/calendar/view.php?view=month
privatefiles,moodle|/user/files.php';
// Set the new configuration back.
set_config('customusermenuitems', $newcustomusermenuitems);
} else {
// If the site is not using the old defaults, only add necessary entries.
$lines = explode("\n", $currentcustomusermenuitems);
$lines = array_map('trim', $lines);

// Remove the Preference entry from the menu to prevent duplication
// since it will be added again in user_get_user_navigation_info().
$lines = array_filter($lines, function($value) {
return strpos($value, 'preferences,moodle|/user/preferences.php') === false;
});

$matches = preg_grep('/\|\/user\/files.php/i', $lines);
if (!$matches) {
// Add the Private files entry to the menu.
$lines[] = 'privatefiles,moodle|/user/files.php';
}

$matches = preg_grep('/\|\/user\/profile.php/i', $lines);
if (!$matches) {
// Add the Profile entry to top of the menu.
array_unshift($lines, 'profile,moodle|/user/profile.php');
}

// Set the new configuration back.
set_config('customusermenuitems', implode("\n", $lines));
}

// Main savepoint reached.
upgrade_main_savepoint(true, 2021121000.01);
}

return true;
}
4 changes: 2 additions & 2 deletions lib/tests/behat/userfeedback.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Feature: Gathering user feedback
| userfeedback_nextreminder | 2 |
| userfeedback_remindafter | 90 |
When I log in as "admin"
And I follow "Dashboard" in the user menu
And I follow "Dashboard"
And I click on "Remind me later" "link"
And I reload the page
Then I should not see "Give feedback" in the "region-main" "region"
Expand All @@ -42,7 +42,7 @@ Feature: Gathering user feedback
| userfeedback_nextreminder | 2 |
| userfeedback_remindafter | 90 |
When I log in as "admin"
And I follow "Dashboard" in the user menu
And I follow "Dashboard"
And I click on "Give feedback" "link"
And I close all opened windows
And I reload the page
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/navigation/output/primary_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function test_primary_export(bool $withcustom, bool $withlang, string $us
if (isloggedin() && !isguestuser()) {
// Look for a language menu item within the user menu items.
$usermenulang = array_filter($data['user']['items'], function($usermenuitem) {
return $usermenuitem->title === get_string('language');
return $usermenuitem->itemtype !== 'divider' && $usermenuitem->title === get_string('language');
});
if ($withlang) { // If multiple languages are installed.
// Assert that the language menu exists within the user menu.
Expand Down
32 changes: 16 additions & 16 deletions lib/tests/user_menu_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,30 @@ public function custom_user_menu_data() {

// These are valid but have an invalid string identifiers or components. They will still produce a menu
// item, and no exception should be thrown.
array('#my1files,moodle|/user/files.php|download', 1, 0),
array('#my1files,moodleakjladf|/user/files.php|download', 1, 0),
array('#my1files,a/b|/user/files.php|download', 1, 0),
array('#my1files,#b|/user/files.php|download', 1, 0),
array('#my1files,moodle|/user/files.php', 1, 1),
array('#my1files,moodleakjladf|/user/files.php', 1, 1),
array('#my1files,a/b|/user/files.php', 1, 1),
array('#my1files,#b|/user/files.php', 1, 1),

// These are unusual, but valid and will generate a menu entry (no filler).
array('-|-|-|-', 1, 0),
array('-|-|-', 1, 0),
array('-|-', 1, 0),
array('#f234|2', 1, 0),
array('-|-|-|-', 1, 1),
array('-|-|-', 1, 1),
array('-|-', 1, 1),
array('#f234|2', 1, 1),

// This is a pretty typical entry.
array('messages,message|/message/index.php|message', 1, 0),
array('messages,message|/message/index.php', 1, 1),

// And these are combinations containing both valid and invalid.
array('messages,message|/message/index.php|message
privatefiles,moodle|/user/files.php|download
array('messages,message|/message/index.php
privatefiles,moodle|/user/files.php
###
badges,badges|/badges/mybadges.php|award
-|-|-
badges,badges|/badges/mybadges.php
-|-
test
-
#####
#f234|2', 5, 2),
#f234|2', 5, 3),
);
}

Expand Down Expand Up @@ -95,8 +95,8 @@ public function test_custom_user_menu($data, $entrycount, $dividercount) {
// We always add two dividers as standard.
$dividercount += 2;

// The basic entry count will additionally include the wrapper menu, Dashboard, Profile, Logout and switch roles link.
$entrycount += 4;
// The basic entry count will additionally include the wrapper menu, Preferences, Logout and switch roles link.
$entrycount += 3;

$output = $OUTPUT->user_menu($USER);
preg_match_all('/<a [^>]+role="menuitem"[^>]+>/', $output, $results);
Expand Down
Loading

0 comments on commit 8c33689

Please sign in to comment.