Custom menus not working (…with custom pages)

Custom menus not working (…with custom pages)

by David Leeding -
Number of replies: 5

Hi

Background

We have developed a Moodle plugin (we call it “the portal”) that displays a set of custom pages. These pages are built to look like standard Moodle pages, complete with header, footer, and Moodle custom menus. The theme we use is a customised clone of "Clean", and we add custom menus via renderers.php. 

The Problem

The custom menus no longer work on our portal pages. When we click on a top level menu item, we see something like #cm_submenu_x appended to the URL, but the submenu doesn’t open. (Top-level Menu links still work if they don’t contain a sub-menu.) However, the menus do work correctly for all standard Moodle pages, and so I don't think this is a problem with the theme per se

I suspect that in building our portal pages, we have missed something important! But what? I’m at a loss to work out what’s gone wrong!

Here's a screen shot of what happens when a menu is clicked on a Portal page (note the URL):

Menu Issue in Portal

 

And here's what happens on standard Moodle pages:

Menu in Standard Moodle Page

 

Observations

  • The submenu items are visible in the code when "View page source" is selected.
  • The debug panel in Chrome doesn’t reveal any JavaScript bugs or warnings.
  • The problem occurs in latest versions of Chrome, Firefox and IE.
  • The problem also occurs with the unaltered “Clean” theme. The problem does not occur with non-bootstrap themes.
  • The menus were working on custom pages in a previous version of Moodle with a non-bootstrap theme.
  • We first noticed this problem after upgrading to Moodle 2.6 from an earlier 2.6 release candidate or beta. We’re currently using Moodle 2.6.1+ (Build: 20140117).

More Info

All our custom portal pages include the following:

     $PAGE->set_context( context_system::instance() );
     $PAGE->set_pagelayout('base');
     $PAGE->set_title( $pagetitle ); // $pagetitle is a simple string
     $PAGE->set_heading( $blockname ); // $blockname is a simple string
     $PAGE->set_focuscontrol('');
     $PAGE->set_cacheable(true);
     $PAGE->navbar->ignore_active();  // Clear any existing navigation settings
     $PAGE->navbar->add($homepagename,
                    new moodle_url( $CFG->wwwroot . '/course/view.php?id=' . $homepageid  )  );
     // Campus name and campus home page course ID for current user
     $PAGE->navbar->add( $alinks[$i]['name'], $alinks[$i]['url'] );
     // The above sits in a loop and builds the breadcrumb from items stored in the $alinks array
     $OUTPUT->header();

 

Maybe I’ve missed or misused something?? Some of our code is now a couple of years old so maybe we've overlooked a change introduced in recent Moodle versions??

I’d be very grateful if anyone could show me where we might have gone wrong, or suggest a way to fix this issue.

Thanks!

David 

 

Average of ratings: -
In reply to David Leeding

Re: Custom menus not working (…with custom pages)

by Michael Milette -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi David,

Debugging Technique #1

Validate your HTML and your CSS on the W3C validators. I've been amazed at times on how something seemingly completely unrelated can often end up being the source of a problem... and it only shows up on some pages or on some sites.

Debugging Technique #2

Sounds like the problem is CSS related. Verify the following:

  • Text and background is visible and in visible colours.
  • The container (div, span, li, etc) is visible.
  • It is appearing where it is supposed to be and not off on in some other part of the screen.
  • The z-order is putting it in front of everything else.
  • Check all of the above for parent containers as well. Even though a div might be visible, if it is in another that is not, all the trying in the world won't make it visible.
  • Using a browser debugger like the one in Firefox, keep turning visibility on or turning styles off for everything until your menu appears. Start from there to figure out what wasn't turned on.

Not all browser debuggers are created equally. What can be invisible in one browser's debugger can be obvious in another. Try a different browser's debugger. IE, Firefox and Chrome all come with one now. You can also give Firebug a try. Many people don't realize that there is also a Lite version available for IE and Chrome.

All this can be quite time consuming, especially if your code works on one site and not on another. Technique #3 below might yield faster results.

Debugging Technique #3

One of the debugging techniques I use when I am stumped is to take the source code from both and slowly convert the non working one into the working one by copying pasting pieces of the code until it start working. Then you know that the problem is in the last piece of code you copied.

You may need to fix some paths if you are debugging locally or using one of the real-time HTML editors out there but that shouldn't be too difficult using a few quick search and replaces.

Remember, all things being identical, only the differences can result in your problem. Sometimes, it might even be a difference in the server and have nothing to do with your code.

Keep what is meaningful to you in all of this and forget the rest. Not everyone is ready for these solutions.

Best regards,

   Michael

In reply to Michael Milette

Re: Custom menus not working (…with custom pages)

by Sue M. -

I just upgraded from 2.5 to 2.8 and suddenly I'm having this issue as well. I looked in the bug trackers and it is a known issue that has no resolution after months... so I thought I'd check in with you, did you ever find a solution for this that worked?

Thanks!

In reply to Sue M.

Re: Custom menus not working (…with custom pages)

by Michael Milette -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

We don't use Moodle 2.8 yet but I just tried it and there is definitely something that is broken or changed in the custom menu code.

If you've got a production site and need an urgent but can do with a less than elegant fix, try adding blank "-" entry right after last level that is showing up. It worked for me however your mileage may vary depending on your theme.

Example:

   -Menu 1
   - <- Insert this (causes a blank entry in you menu)
   --Submenu 1|/link1.php <- These submenus now show up.
   --Submenu 2|/link2.php
   --Submenu 3|/link3.php

Looks kind of weird and it resulted in some formatting issues in my case but the missing entries re-appeared in my case.

Hope this helps.

Best regards,

Michael Milette

In reply to Sue M.

Re: Custom menus not working (…with custom pages)

by Michael Milette -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Sue,

I was curious as to why sometimes it seemed to work for me while other times it didn't so I did a little more investigating.

What I discovered is that it happens when you use the language parameters to specify for alternate languages. For example:

Support|||en
-Moodle Sites|||en
-Site de Moodle|||fr
--Moodle.com|http://moodle.com/||en <- These two lines DO NOT show up.
--Moodle free support|https://moodle.org/support||en <- These two lines DO NOT show up.
-Moodle development|||en
--Development|https://moodle.org/development||en <- These two lines DO show up.
--Documentation|http://docs.moodle.org|Moodle Docs||en <- These two lines DO show up
-Search Engines|||en
--Google|http://www.google.com||en
--Bing|http://www.bing.com||en

Can you share the Tracker number for the related open issue? This new important information could help developers reproduce the issue consistently and implement a fix for it in the near future.

Best regards,

     Michael


In reply to Michael Milette

Re: Custom menus not working (…with custom pages)

by Michael Milette -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

In case others want to follow this, I think I may have figured out where and when the problem was introduced. See MDL-46652. I've recommended re-opening the issue.

Michael