mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 17:06:53 +02:00
MDL-72783 usertours: Improve the tours maching
Improve the regex so the Tour can detect the URL match is pointing to Dashboard (/my/) or My Course (/my/courses.php) correctly
This commit is contained in:
parent
524f75797a
commit
87f233e698
2 changed files with 13 additions and 4 deletions
|
@ -84,13 +84,22 @@ EOF;
|
||||||
// Attempt to determine whether this is the front page.
|
// Attempt to determine whether this is the front page.
|
||||||
// This is a special case because the frontpage uses a shortened page path making it difficult to detect exactly.
|
// This is a special case because the frontpage uses a shortened page path making it difficult to detect exactly.
|
||||||
$isfrontpage = $targetmatch->compare(new \moodle_url('/'), URL_MATCH_BASE);
|
$isfrontpage = $targetmatch->compare(new \moodle_url('/'), URL_MATCH_BASE);
|
||||||
|
$isdashboard = $targetmatch->compare(new \moodle_url('/my/'), URL_MATCH_BASE);
|
||||||
$target = $targetmatch->out_as_local_url();
|
$target = $targetmatch->out_as_local_url();
|
||||||
return array_filter($tours, function($tour) use ($isfrontpage, $target) {
|
return array_filter($tours, function($tour) use ($isfrontpage, $isdashboard, $target) {
|
||||||
if ($isfrontpage && $tour->pathmatch === 'FRONTPAGE') {
|
if (($isfrontpage || $isdashboard) && $tour->pathmatch === 'FRONTPAGE') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$pattern = preg_quote($tour->pathmatch, '@');
|
$pattern = preg_quote($tour->pathmatch, '@');
|
||||||
|
if (strpos($pattern, '%') !== false) {
|
||||||
|
// The URL match format is something like: /my/%.
|
||||||
|
// We need to find all the URLs which match the first part of the pattern.
|
||||||
$pattern = str_replace('%', '.*', $pattern);
|
$pattern = str_replace('%', '.*', $pattern);
|
||||||
|
} else {
|
||||||
|
// The URL match format is something like: /my/courses.php.
|
||||||
|
// We need to find all the URLs which match with whole pattern.
|
||||||
|
$pattern .= '$';
|
||||||
|
}
|
||||||
return !!preg_match("@{$pattern}@", $target);
|
return !!preg_match("@{$pattern}@", $target);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,7 +164,7 @@ class cache_testcase extends advanced_testcase {
|
||||||
'Matches expected glob' => [
|
'Matches expected glob' => [
|
||||||
$tourconfigs,
|
$tourconfigs,
|
||||||
'/my/index.php',
|
'/my/index.php',
|
||||||
['my_glob_1', 'my_glob_2'],
|
['my_glob_1', 'my_glob_2', 'frontpage_match'],
|
||||||
],
|
],
|
||||||
'Matches expected glob and exact' => [
|
'Matches expected glob and exact' => [
|
||||||
$tourconfigs,
|
$tourconfigs,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue