From 2ae5a92733365606cccb480af7bd96afc6cbcb18 Mon Sep 17 00:00:00 2001 From: yusufwib01 Date: Thu, 5 Jun 2025 03:40:58 +0700 Subject: [PATCH] MDL-76414 navigation: Show 'Calendar' link in primary nav to guests --- lib/classes/navigation/views/primary.php | 10 ++++++++++ lib/tests/navigation/views/primary_test.php | 2 +- theme/boost/tests/behat/primarynav.feature | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/classes/navigation/views/primary.php b/lib/classes/navigation/views/primary.php index f02bf3ebf34..4df6ac8f0b4 100644 --- a/lib/classes/navigation/views/primary.php +++ b/lib/classes/navigation/views/primary.php @@ -72,6 +72,12 @@ class primary extends view { } } + // Add the calendar link only for guest users. + if (isguestuser()) { + $this->add(get_string('calendar', 'calendar'), new \moodle_url('/calendar/view.php?view=month'), self::TYPE_ROOTNODE, + null, 'calendar'); + } + $showsiteadminnode = empty($this->page->theme->removedprimarynavitems) || !in_array('siteadminnode', $this->page->theme->removedprimarynavitems); @@ -133,6 +139,10 @@ class primary extends view { if ($this->context->contextlevel == CONTEXT_COURSECAT || $node->search_for_active_node(URL_MATCH_EXACT)) { $activekey = 'siteadminnode'; } + } else if (in_array('calendar', $children) && $node = $this->find('calendar', self::TYPE_ROOTNODE)) { + if ($node->search_for_active_node(URL_MATCH_BASE)) { + $activekey = 'calendar'; + } } if ($activekey && $activenode = $this->find($activekey, null)) { diff --git a/lib/tests/navigation/views/primary_test.php b/lib/tests/navigation/views/primary_test.php index 2498d8e705a..315e1732348 100644 --- a/lib/tests/navigation/views/primary_test.php +++ b/lib/tests/navigation/views/primary_test.php @@ -61,7 +61,7 @@ final class primary_test extends \advanced_testcase { */ public static function setting_initialise_provider(): array { return [ - 'Testing as a guest user' => ['guest', ['home']], + 'Testing as a guest user' => ['guest', ['home', 'calendar']], 'Testing as an admin' => ['admin', ['home', 'myhome', 'mycourses', 'siteadminnode']], 'Testing as a regular user' => ['user', ['home', 'myhome', 'mycourses']] ]; diff --git a/theme/boost/tests/behat/primarynav.feature b/theme/boost/tests/behat/primarynav.feature index f1fe69c07f2..8bf74273093 100644 --- a/theme/boost/tests/behat/primarynav.feature +++ b/theme/boost/tests/behat/primarynav.feature @@ -58,10 +58,11 @@ Feature: Primary navigation And I should see "Dashboard" in the "page-header" "region" @theme_boost - Scenario: Guest users can only see the Home item in the primary navigation menu + Scenario: Guest users can only see the Home and Calendar items in the primary navigation menu Given I log in as "guest" When I am on site homepage Then I should see "Home" in the ".primary-navigation" "css_element" + And I should see "Calendar" in the ".primary-navigation" "css_element" And I should not see "Dashboard" in the ".primary-navigation" "css_element" And I should not see "My courses" in the ".primary-navigation" "css_element" And I should not see "Site administration" in the ".primary-navigation" "css_element"