When a user views an activity in a course, Moodle displays breadcrumbs <Site name> -> <Course name> -> <Activity type> -> <Activity name>. The activity type (e.g. 'Forums' or 'Quizzes') crumb is not very useful to most users and adds unnecessary clutter. A number of our clients have requested that it be removed.
Therefore, I wrote a patch to add an option to hide this breadcrumb either from everybody or from all but teachers. The current behavior of showing it to everybody remains the default, but there is a new option under the site configuration for this to be hidden as desired.
The patch (against Moodle 1.7.1+) is attached. What do other users think? Would anyone else find this useful? We would like to see this patch included in the next version of Moodle.
There has been discussion and hacks posted about this subject before. I am one of those who typically does NOT like the index pages in the breadcrumb (I get complaints/questions about it frequently) and hack it out. I feel that the activities block is a much better way to allow users access to the index pages.
Thanks for sharing your code.
Furthermore, looking at the patch, it seems to significantly tidy up the code (moving duplicated code up to parent class), and may actually reduce the overall number of lines while adding this feature.
For this additional feature, I see benefit to many users, and I am not currently seeing a cost - why not apply it to moodle core?
If this patch were provided on top of cvshead (and/or 1.8???) is there a reason it couldn't be applied?
Re: Removing activity type breadcrumbs - MartinD review?
It's a good patch, but it changes a key part of Moodle UI and I am kind of wary of merging it in. IIRC, there's been some flamefesting on this before, and I'm personally divided over it so... MartinD?
(Actually, Peter, Andrew, can you guys post a patch against HEAD for this?)
Re: Removing activity type breadcrumbs - MartinD review?
What about the option to turn on/off breadcrumbs in Config? Keeps all happy then.
Re: Removing activity type breadcrumbs - MartinD review?w
<Site name> -> <Category(ies)>-><Course name> -> <Activity type> -> <Activity name>.
where Categories and Activity type could be hidden or shown at will independently.
Re: Removing activity type breadcrumbs - MartinD review?
The original method of passing the navigation "breadcrumbs" as a string is the real problem here (it was an early decision of mine that I deeply regret). If we are going to spend the time fixing this let's do it properly so we never have to worry about it again.
What I think we need to have is a new function that is called from module land (eg build_navigation()) that accepts an array of $name=>$links as well as a few other common environement objects like $cm and $course.
This function would take all this environment data, combine it with admin and/or user settings (eg showcategorylinks, showindexlinks) and return a formatted XHTML string, which we could then pass to print_header(). We may need to pass it in such a way (in an object perhaps) so that we can distinguish between this and an ordinary legacy navigation string.
Finally, we then need to rewrite all the core pages to use this function so we get the maximum benefits.
Is anyone up to the challenge?
As well as what you pointed out, I've recently been having a more serious look around, and found _many_ more places that need changes than I originally thought.
I haven't forgotten this train of thought though ...
* Introduces build_navigation() that takes an array of links and builds an XHTML breadcrumb trail.
* links can be filtered based on a 'type' attribute that each link passed into build_navigation() must supply.
* Maintains compatibility with legacy code - the output of build_navigation() is an array that print_navigation() can distinguish from legacy breadcrumbs.
* Adds a config option to turn off the 'activity type' component of the breadcrumbs.
* Each module has been modified to use build_navigation()
The patch series applied to yesterdays CVSHead can be found here:
http://git.catalyst.net.nz/gitweb?p=moodle-r2.git;a=shortlog;h=mattc3
For a good example of how build_navigation() is used in module space take a look at this patch:
http://git.catalyst.net.nz/gitweb?p=moodle-r2.git;a=commitdiff;h=89e9d5d88b23d9a2d225c12a99a6cda7ad8ff755
Let me know your thoughts on this patch series.
Cheers,
Matt.
http://tracker.moodle.org/browse/MDL-1074
but it would have been a pig of a job with the old breadcrumbs, but the build_navigation function makes it much more do-able.
I would be interested in your views on how to implement the above (that is have section name in the breadcrumbs rather than activity type). You could just add the section name breadcrumb at the module level, but this seems to me to be duplicating code across the modules. I think a better option would be to pass the cm_id to build_navigation, and put the checks there to see if section name is set and if so whether to include it or not. Martin mentioned the option in his post on this subject of passing the likes of $cm and $course to a build_navigation function.
As a test I have done a quick hack myself to pass cm_id through from the assignment module to build_navigation, and from there done a get_record_sql to get the section id and summary and added this to the breadcrumbs - it works ok, but I am fairly new to hacking around in Moodle, and the section summary, etc. may already be floating around in another global variable that can be more easily picked up by build_navigation - any help/suggestions appreciated
regards
Glen
I would add $cm_id as an optional parameter to build_navigation() and put the logic of retrieving and formatting the section summary inside build_navigation().
If I recall correctly the section summary is an HTML text field so making this work well in the navigation may be a little tricky - you would need to strip the html from the field and truncate it, however the risk is that the resulting text may not be very meaning full if the summary has not been well structured by the course creator.
Regards,
Matt.
Thanks-Alex
Can anyone tell me how to install this patch? Is it a manual process requiring major code hacks or is there an easier way?
Thanks.
Brian
Hi,
I tried to follow the patch. I'm running moodle 1.7 and I simply can't seem to locate the admin/configvars.php. All the rest are okay and configured, except the missing file. Can you tell me where the configvars.php is in moodle 1.7?
Thanks
James
This patch is exaclty what I was looking for. 3 questions... What do I need to rename the file ext to and where does it need to be put? Is it compatible with 1.8.1?
Thanks,
Donald
I keep meaning to write a companion page for http://docs.moodle.org/en/Development:How_to_create_a_patch. Basically there are various tool that will do it for you, depending on which operating system you use. Command-line 'diff' had partner 'patch' that does the trick. Eclipse will certainly do it. WinMerge keep promising that they will implement this functionality in a future release, but I think they are still not there yet.
I have a similar issue. Some our teachers ask for displaying the whole course category path in the navigation trail. I fully understand the request as it is something they know from other websites. In some cases, a teacher often needs to go back to the list of courses in the current category. It is a little bit annoying to go back to the front page and navigate through the categories again.
IMHO there should be a setting like showcategorylinks as MartinD has mentioned above. But reading beta4 build_navigation() sources, categories are not considered at all.
Also, from my point of view, these settings (i.e. whether to display activity type, categories etc. or not) should be moved into user profile space. It is similar setting as whether to use wysiwyg, ajax etc. Any chances to do it for 1.9 yet?
// Course name, if appropriate. if (isset($COURSE) && $COURSE->id != SITEID) {
add:
// ou-specific begins if ($CFG->ousite=='OCI') { // Make the breadcrumb include the category/subcategory path require_once( $CFG->dirroot.'/local/ocilib.php' ); // Get the category path. $category_path = oci_category_path( $COURSE->category ); // Put in the All Topics link $strcategories = get_string('allcategories'); $navlinks[] = array('name' => $strcategories, 'link' => $CFG->wwwroot.'/course/index.php', 'type' => 'misc'); // Put in each of the category links foreach( $category_path as $cat_id => $cat_name ) { $navlinks[] = array('name' => $cat_name, 'link' => $CFG->wwwroot.'/course/category.php?id='.$cat_id, 'type' => 'misc'); } } // ou-specific ends
it uses the following function:
/** * get the category as a path (e.g., tom/dick/harry) * @param int id the id of the most nested catgory * @param string delimiter the delimiter you want * @return string the path */ function oci_category_path( $parentid ) { $path = ''; do { if (!$category = get_record( 'course_categories','id',$parentid )) { print_error( "Error reading category record - $parentid" ); } $name = $category->name; $parentid = $category->parent; $id = $category->id; if (!empty($path)) { $path = "$id|{$name}-{$path}"; } else { $path = "$id|{$name}"; } } while ($parentid != 0); // Now split the path back down and create an array to hold the // category/subcategory structure $temp_categories = explode( '-', $path ); foreach( $temp_categories as $cat ) { list( $cat_id, $cat_name ) = explode( '|', $cat ); $categories[$cat_id] = $cat_name; } return $categories; }
Of course, you may want to tweak this to meet exactly your requirements.
This could be cleaned up and committed to 1.9 or 2.0 dev, I suppose.I'm not sure it should really be a user preference. Certainly, we wouldn't like that here at the OU, we would want it to be a system preference. But you could debate that for ever.
Hello Tim
We need categories in the breadcrumb and used to implement it by adding the attached code to the header file. Since 1.9, the $navigation no longer accepts " around it, so we removed it. Now the category in breadcrumb code no longer works, as when left in it returns anything after the category as "array". Without the code the breadcrumb works fine, just without the categories.
Would the OU "hack' work for us, and if so, where can I find "build_navigation", or do you know of a way to add it to the header like we did?
Thanks for any help, Peter
You really ought to develop a technique for finding any function by name if you are doing muc Moodle development (for example, use an editor with good built-in search), but to save you searching this time, I'll tell you it is about line 3650 of lib/weblib.php.
Thanks, - point taken
Some editors have support for the tabs file. I've failed to get my emacs to play with it properly though
IMHO Martín meant "tags file". My ViM works perfectly with it, I can just press Ctrl+[ and I am thrown directly into the function definition
