Skip to content

Commit

Permalink
MDL-71084 core_navigation: Provide a header title and active node text
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Dias committed Mar 23, 2021
1 parent 4c26696 commit 0c7c677
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lang/en/moodle.php
Expand Up @@ -35,6 +35,7 @@
$string['activity'] = 'Activity';
$string['activityclipboard'] = 'Moving this activity: {$a}';
$string['activityiscurrentlyhidden'] = 'Sorry, this activity is currently hidden';
$string['activityheader'] = 'Activity menu';
$string['activitymodule'] = 'Activity module';
$string['activitymodules'] = 'Activity modules';
$string['activityreport'] = 'Activity report';
Expand Down Expand Up @@ -310,6 +311,7 @@
$string['counteditems'] = '{$a->count} {$a->items}';
$string['country'] = 'Country';
$string['course'] = 'Course';
$string['courseheader'] = 'Course menu';
$string['courseadministration'] = 'Course administration';
$string['courseapprovedemail'] = 'Your requested course, {$a->name}, has been approved and you have been made a {$a->teacher}. To access your new course, go to {$a->url}';
$string['courseapprovedemail2'] = 'Your requested course, {$a->name}, has been approved. To access your new course, go to {$a->url}';
Expand Down Expand Up @@ -1195,6 +1197,7 @@
$string['logtoomanycourses'] = '[ <a href="{$a->url}">more</a> ]';
$string['logtoomanyusers'] = '[ <a href="{$a->url}">more</a> ]';
$string['lookback'] = 'Look back';
$string['menu'] = 'Menu';
$string['mailadmins'] = 'Inform admins';
$string['mailstudents'] = 'Inform students';
$string['mailteachers'] = 'Inform teachers';
Expand Down
5 changes: 5 additions & 0 deletions lib/classes/navigation/views/secondary.php
Expand Up @@ -30,6 +30,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class secondary extends view {
/** @var string $headertitle The header for this particular menu*/
public $headertitle;
/**
* Defines the default structure for the secondary nav in a course context.
*
Expand Down Expand Up @@ -116,14 +118,17 @@ public function initialise(): void {
}
$this->id = 'secondary_navigation';
$context = $this->context;
$this->headertitle = get_string('menu');

switch ($context->contextlevel) {
case CONTEXT_COURSE:
if ($this->page->course->id != $SITE->id) {
$this->headertitle = get_string('courseheader');
$this->load_course_navigation();
}
break;
case CONTEXT_MODULE:
$this->headertitle = get_string('activityheader');
$this->load_module_navigation();
break;
case CONTEXT_SYSTEM:
Expand Down
4 changes: 4 additions & 0 deletions lib/classes/navigation/views/view.php
Expand Up @@ -36,6 +36,8 @@ abstract class view extends navigation_node {
protected $page;
/** @var bool $initialised A switch to see if the navigation node is initialised */
protected $initialised = false;
/** @var navigation_node $activenode A string identifier for the active node*/
public $activenode;

/**
* Function to initialise the respective view
Expand Down Expand Up @@ -116,7 +118,9 @@ protected function scan_for_active_node(navigation_node $node): ?navigation_node
$child->make_inactive();
} else {
$child->make_active();
$this->activenode = $child;
}

return $node; // We have found the active node, set the parent status, no need to continue.
}
}
Expand Down
15 changes: 10 additions & 5 deletions lib/tests/secondary_test.php
Expand Up @@ -81,9 +81,12 @@ public function leaf_nodes_order_provider(): array {
*
* @param string $context The context to setup for - course, module, system
* @param string $expectedfirstnode The expected first node
* @param string $header The expected string
* @param string $activenode The expected active node
* @dataProvider test_setting_initialise_provider
*/
public function test_setting_initialise(string $context, string $expectedfirstnode) {
public function test_setting_initialise(string $context, string $expectedfirstnode,
string $header, string $activenode) {
global $PAGE, $SITE;
$this->resetAfterTest();
$this->setAdminUser();
Expand Down Expand Up @@ -116,7 +119,9 @@ public function test_setting_initialise(string $context, string $expectedfirstno
$node = new secondary($PAGE);
$node->initialise();
$children = $node->get_children_key_list();
$this->assertEquals($children[0], $expectedfirstnode);
$this->assertEquals($expectedfirstnode, $children[0]);
$this->assertEquals(get_string($header), $node->headertitle);
$this->assertEquals($activenode, $node->activenode->text);
}

/**
Expand All @@ -125,9 +130,9 @@ public function test_setting_initialise(string $context, string $expectedfirstno
*/
public function test_setting_initialise_provider(): array {
return [
'Testing in a course context' => ['course', 'coursehome'],
'Testing in a module context' => ['module', 'modulepage'],
'Testing in a site admin' => ['system', 'siteadminnode'],
'Testing in a course context' => ['course', 'coursehome', 'courseheader', 'Course Page'],
'Testing in a module context' => ['module', 'modulepage', 'activityheader', 'Activity'],
'Testing in a site admin' => ['system', 'siteadminnode', 'menu', 'Site administration'],
];
}
}

0 comments on commit 0c7c677

Please sign in to comment.