MDL-78656 output: display menu item titles in primary navigation.

Since custom menu items were merged into the primary navigation/more
menu as part of 56c34d71 and related work, the "title" attribute of
each custom menu item was lost.
This commit is contained in:
Paul Holden 2023-07-06 12:03:10 +01:00
parent f12e1b82a0
commit f7b3caac2c
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164
2 changed files with 29 additions and 7 deletions

View File

@ -575,11 +575,20 @@ class navigation_node implements renderable {
/**
* Sets the title for this node and forces Moodle to utilise it.
* @param string $title
*
* Note that this method is named identically to the public "title" property of the class, which unfortunately confuses
* our Mustache renderer, because it will see the method and try and call it without any arguments (hence must be nullable)
* before trying to access the public property
*
* @param string|null $title
* @return string
*/
public function title($title) {
$this->title = $title;
$this->forcetitle = true;
public function title(?string $title = null): string {
if ($title !== null) {
$this->title = $title;
$this->forcetitle = true;
}
return (string) $this->title;
}
/**

View File

@ -34,6 +34,7 @@
<li class="dropdown nav-item" role="none" data-forceintomoremenu="{{#forceintomoremenu}}true{{/forceintomoremenu}}{{^forceintomoremenu}}false{{/forceintomoremenu}}">
<a class="dropdown-toggle nav-link {{#isactive}}active{{/isactive}} {{#classes}}{{.}} {{/classes}}" id="drop-down-{{moremenuid}}" role="menuitem" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false" href="#" aria-controls="drop-down-menu-{{moremenuid}}"
{{#title}}title="{{.}}"{{/title}}
{{#isactive}}aria-current="true"{{/isactive}}
{{^isactive}}tabindex="-1"{{/isactive}}
>
@ -44,6 +45,7 @@
{{^divider}}
{{#is_action_link}}
<a class="dropdown-item" role="menuitem" {{#actionattributes}}{{name}}="{{value}}" {{/actionattributes}} href="{{{url}}}{{{action}}}"
{{#title}}title="{{.}}"{{/title}}
data-disableactive="true" tabindex="-1"
>
{{{text}}}
@ -53,7 +55,11 @@
{{/action_link_actions}}
{{/is_action_link}}
{{^is_action_link}}
<a class="dropdown-item" role="menuitem" href="{{{url}}}{{{action}}}" {{#isactive}}aria-current="true"{{/isactive}} tabindex="-1">{{{text}}}</a>
<a class="dropdown-item" role="menuitem" href="{{{url}}}{{{action}}}" {{#isactive}}aria-current="true"{{/isactive}} tabindex="-1"
{{#title}}title="{{.}}"{{/title}}
>
{{{text}}}
</a>
{{/is_action_link}}
{{/divider}}
{{#divider}}
@ -67,7 +73,9 @@
<li data-key="{{key}}" class="nav-item" role="none" data-forceintomoremenu="{{#forceintomoremenu}}true{{/forceintomoremenu}}{{^forceintomoremenu}}false{{/forceintomoremenu}}">
{{#istablist}}
{{#is_action_link}}
<a role="tab" class="nav-link {{#classes}}{{.}} {{/classes}}" href="{{tab}}" data-toggle="tab" data-text="{{{text}}}" data-disableactive="true" tabindex="-1">
<a role="tab" class="nav-link {{#classes}}{{.}} {{/classes}}" href="{{tab}}" data-toggle="tab" data-text="{{{text}}}" data-disableactive="true" tabindex="-1"
{{#title}}title="{{.}}"{{/title}}
>
{{{text}}}
</a>
{{#action_link_actions}}
@ -77,6 +85,7 @@
{{^is_action_link}}
<a role="tab" class="nav-link {{#isactive}}active{{/isactive}} {{#classes}}{{.}} {{/classes}}"
href="{{tab}}" data-toggle="tab" data-text="{{{text}}}"
{{#title}}title="{{.}}"{{/title}}
{{#isactive}}aria-selected="true"{{/isactive}}
{{^isactive}}tabindex="-1"{{/isactive}}
>
@ -86,7 +95,10 @@
{{/istablist}}
{{^istablist}}
{{#is_action_link}}
<a role="menuitem" class="nav-link {{#classes}}{{.}} {{/classes}}" {{#actionattributes}}{{name}}="{{value}}" {{/actionattributes}} href="{{{url}}}{{{action}}}" data-disableactive="true" tabindex="-1">
<a role="menuitem" class="nav-link {{#classes}}{{.}} {{/classes}}" {{#actionattributes}}{{name}}="{{value}}" {{/actionattributes}} href="{{{url}}}{{{action}}}"
{{#title}}title="{{.}}"{{/title}}
data-disableactive="true" tabindex="-1"
>
{{{text}}}
</a>
{{#action_link_actions}}
@ -96,6 +108,7 @@
{{^is_action_link}}
<a role="menuitem" class="nav-link {{#isactive}}active{{/isactive}} {{#classes}}{{.}} {{/classes}}"
href="{{{url}}}{{{action}}}"
{{#title}}title="{{.}}"{{/title}}
{{#isactive}}aria-current="true"{{/isactive}}
{{^isactive}}tabindex="-1"{{/isactive}}
>