Merge branch 'MDL-87543-main' of https://github.com/yusufwib01/moodle

This commit is contained in:
Huong Nguyen
2026-02-03 10:10:54 +07:00
3 changed files with 78 additions and 0 deletions
+1
View File
@@ -45,6 +45,7 @@ $string['courseshortname'] = 'Shortname';
$string['courseshortname_help'] = 'Enter a short name for your course. It does not need to be unique.';
$string['coursesnumber'] = 'Number of courses ({$a})';
$string['dbtype'] = 'Database type ({$a})';
$string['defaulthomepage'] = 'Start page for users ({$a})';
$string['demourl'] = 'Demo URL';
$string['demourl_help'] = 'Enter the demo URL of your course. By default it is the URL of your course. The demo URL is displayed as a link in a search result.';
$string['diskusagesize'] = 'Disk usage size ({$a} MB)';
+37
View File
@@ -70,6 +70,8 @@ class registration {
2023081200 => ['aiusage'],
// Disk usage added in Moodle 5.2.
2025100900 => ['diskusage'],
// Default homepage added in Moodle 5.2.
2026012200 => ['defaulthomepage'],
];
/** @var string Site privacy: not displayed */
@@ -214,6 +216,9 @@ class registration {
// Disk usage size.
$siteinfo['diskusage'] = self::get_dataroot_size() ?? 0;
// Default homepage.
$siteinfo['defaulthomepage'] = get_config('moodle', 'defaulthomepage');
// Primary auth type.
$primaryauthsql = 'SELECT auth, count(auth) as tc FROM {user} GROUP BY auth ORDER BY tc DESC';
$siteinfo['primaryauthtype'] = $DB->get_field_sql($primaryauthsql, null, IGNORE_MULTIPLE);
@@ -305,6 +310,7 @@ class registration {
'pluginusage' => get_string('pluginusagedata', 'hub', $pluginusagelinks),
'aiusage' => $OUTPUT->render_from_template('core/ai_usage_data', ['aiusagedata' => self::show_ai_usage()]),
'diskusage' => get_string('diskusagesize', 'hub', $siteinfo['diskusage']),
'defaulthomepage' => get_string('defaulthomepage', 'hub', self::get_defaulthomepage_name($siteinfo['defaulthomepage'])),
];
foreach ($senddata as $key => $str) {
@@ -968,4 +974,35 @@ class registration {
public static function reset_caches(): void {
self::$registration = null;
}
/**
* Returns the title for the defaulthomepage setting value.
*
* @param int|string $value The defaulthomepage value (constant or URL)
* @return string The title
*/
public static function get_defaulthomepage_name($value): string {
// Check for standard homepages.
$options = [
HOMEPAGE_SITE => get_string('home'),
HOMEPAGE_MY => get_string('mymoodle', 'admin'),
HOMEPAGE_USER => get_string('userpreference', 'admin'),
HOMEPAGE_MYCOURSES => get_string('mycourses', 'admin'),
];
if (isset($options[$value])) {
return $options[$value];
}
// Check for custom homepage.
$hook = new \core_user\hook\extend_default_homepage();
\core\di::get(\core\hook\manager::class)->dispatch($hook);
$customoptions = $hook->get_options();
if (isset($customoptions[$value])) {
return (string)$customoptions[$value];
}
return $value;
}
}
@@ -197,4 +197,44 @@ final class registration_test extends \advanced_testcase {
$this->assertEquals(get_string('time_range', 'hub'), $timerange['label']);
$this->assertTrue(!empty($timerange['values']));
}
/**
* Test getting the title for the defaulthomepage setting value.
*
* @covers \core\hub\registration::get_defaulthomepage_name
*/
public function test_get_defaulthomepage_name(): void {
$this->resetAfterTest();
// Test HOMEPAGE_SITE constant.
$result = registration::get_defaulthomepage_name(HOMEPAGE_SITE);
$this->assertEquals(get_string('home'), $result);
// Test HOMEPAGE_MY constant.
$result = registration::get_defaulthomepage_name(HOMEPAGE_MY);
$this->assertEquals(get_string('mymoodle', 'admin'), $result);
// Test HOMEPAGE_USER constant.
$result = registration::get_defaulthomepage_name(HOMEPAGE_USER);
$this->assertEquals(get_string('userpreference', 'admin'), $result);
// Test HOMEPAGE_MYCOURSES constant.
$result = registration::get_defaulthomepage_name(HOMEPAGE_MYCOURSES);
$this->assertEquals(get_string('mycourses', 'admin'), $result);
// Test custom homepage option via hook.
$customurl = '/local/customhomepage/landing.php';
$customtitle = 'Custom landing page';
$callback = function (\core_user\hook\extend_default_homepage $hook) use ($customurl, $customtitle) {
$hook->add_option(new \core\url($customurl), $customtitle);
};
$this->redirectHook(\core_user\hook\extend_default_homepage::class, $callback);
$result = registration::get_defaulthomepage_name($customurl);
$this->assertEquals($customtitle, $result);
// Test unknown URL.
$result = registration::get_defaulthomepage_name('/unknown/page');
$this->assertEquals('/unknown/page', $result);
}
}