mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-48542 user_menu: add proper divider support
Added divider support to the user menu; hardened the custom user menu against invalid input.
This commit is contained in:
parent
c589b7be4e
commit
22893d6f47
3 changed files with 58 additions and 26 deletions
|
@ -3067,28 +3067,44 @@ EOD;
|
|||
$navitemcount = count($opts->navitems);
|
||||
$idx = 0;
|
||||
foreach ($opts->navitems as $key => $value) {
|
||||
$pix = null;
|
||||
if (isset($value->pix) && !empty($value->pix)) {
|
||||
$pix = new pix_icon($value->pix, $value->title, null, array('class' => 'iconsmall'));
|
||||
} else if (isset($value->imgsrc) && !empty($value->imgsrc)) {
|
||||
$value->title = html_writer::img(
|
||||
$value->imgsrc,
|
||||
$value->title,
|
||||
array('class' => 'iconsmall')
|
||||
) . $value->title;
|
||||
}
|
||||
$al = new action_menu_link_secondary(
|
||||
$value->url,
|
||||
$pix,
|
||||
$value->title,
|
||||
array('class' => 'icon')
|
||||
);
|
||||
$am->add($al);
|
||||
|
||||
// Add dividers after the first item and before the
|
||||
// last item.
|
||||
if ($idx == 0 || $idx == $navitemcount - 2) {
|
||||
$am->add($divider);
|
||||
switch ($value->itemtype) {
|
||||
case 'divider':
|
||||
// If the nav item is a divider, add one and skip link processing.
|
||||
$am->add($divider);
|
||||
$idx++;
|
||||
break;
|
||||
|
||||
case 'invalid':
|
||||
// Silently skip invalid entries (should we post a notification?).
|
||||
break;
|
||||
|
||||
case 'link':
|
||||
// Process this as a link item.
|
||||
$pix = null;
|
||||
if (isset($value->pix) && !empty($value->pix)) {
|
||||
$pix = new pix_icon($value->pix, $value->title, null, array('class' => 'iconsmall'));
|
||||
} else if (isset($value->imgsrc) && !empty($value->imgsrc)) {
|
||||
$value->title = html_writer::img(
|
||||
$value->imgsrc,
|
||||
$value->title,
|
||||
array('class' => 'iconsmall')
|
||||
) . $value->title;
|
||||
}
|
||||
$al = new action_menu_link_secondary(
|
||||
$value->url,
|
||||
$pix,
|
||||
$value->title,
|
||||
array('class' => 'icon')
|
||||
);
|
||||
$am->add($al);
|
||||
|
||||
// Add dividers after the first item and before the
|
||||
// last item.
|
||||
if ($idx == 0 || $idx == $navitemcount - 2) {
|
||||
$am->add($divider);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$idx++;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue