Removing activity type breadcrumbs

Removing activity type breadcrumbs

av Andrew Walbran -
Antall svar: 28
Hello
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.
Gjennomsnittlig vurdering: -
Som svar til Andrew Walbran

Re: Removing activity type breadcrumbs

av Chardelle Busch -
Bilde av Core developers
Hi Andrew,

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.
Som svar til Chardelle Busch

Re: Removing activity type breadcrumbs

av Peter Bulmer -
I think a key point of Andrew's post is that in his patch, the current situation remains the default - this simply enables users like Chardelle, and ourselves to flick a switch to turn this off.

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?

Som svar til Andrew Walbran

Re: Removing activity type breadcrumbs - MartinD review?

av Martín Langhoff -
Just in case anyone wonders -- the patch comes from Andrew and Peter (both catalyst-ers) and I've reviewed it.

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?)
Som svar til Martín Langhoff

Re: Removing activity type breadcrumbs - MartinD review?

av James Cracknell -
Hi

What about the option to turn on/off breadcrumbs in Config? Keeps all happy then.
Som svar til James Cracknell

Re: Removing activity type breadcrumbs - MartinD review?w

av Andrea Bicciolo -
My ++ for the on/off in config.php, or better in Administration block. Since cases vary (peoples ask for no activity type, while others asks also for categories in the breadcrumb) in my opinion the very best would be the following:

<Site name> -> <Category(ies)>-><Course name> -> <Activity type> -> <Activity name>.

where Categories and Activity type could be hidden or shown at will independently.
Som svar til James Cracknell

Re: Removing activity type breadcrumbs - MartinD review?

av Andrew Walbran -
Yes, this is what the patch does. The default is to show the activity type breadcrumb as before, but an option is added to hide it.
Som svar til Andrew Walbran

Re: Removing activity type breadcrumbs

av Martin Dougiamas -
Bilde av Core developers Bilde av Documentation writers Bilde av Moodle HQ Bilde av Particularly helpful Moodlers Bilde av Plugin developers Bilde av Testers
Good effort, thanks ... this patch fixes one issue but unfortunately really doesn't clean up the system to make it flexible for the future.

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? smiler
Som svar til Martin Dougiamas

Re: Removing activity type breadcrumbs

av Peter Bulmer -
Thanks Martin,
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 ... smiler
Som svar til Martin Dougiamas

Re: Removing activity type breadcrumbs

av Matt Clarkson -
Bilde av Core developers Bilde av Peer reviewers Bilde av Plugin developers
I have created a patch series based on the ideas presented in this thread which addresses the following points:

* 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.
Gjennomsnittlig vurdering:Useful (1)
Som svar til Matt Clarkson

Re: Removing activity type breadcrumbs

av Glen Davies -
Thanks for this Matt, I have it working on a 1.9 Dev server. I have been looking at options for implementing the following
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 blunker

regards
Glen


Som svar til Glen Davies

Re: Removing activity type breadcrumbs

av Matt Clarkson -
Bilde av Core developers Bilde av Peer reviewers Bilde av Plugin developers
Hi 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.
Som svar til Matt Clarkson

Re: Removing activity type breadcrumbs

av Alex Sergay -
Matt, this sounds like just what I need. Can you tell me how to install the patches, and which ones I need?
Thanks-Alex
Som svar til Andrew Walbran

Re: Removing activity type breadcrumbs

av Brian Maynes -

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

Som svar til Andrew Walbran

Re: Removing activity type breadcrumbs

av J. Chan -

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

Som svar til J. Chan

Re: Removing activity type breadcrumbs

av Don Sheets -

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

Som svar til Andrew Walbran

How do we install this?

av Logan Modine -
I'm glad I'm not the only one who wants something like this implemented. How does one go about installing this patch? I'm using Moodle 1.8. Thanks!
Som svar til Logan Modine

Re: How do we install this?

av Tim Hunt -
Bilde av Core developers Bilde av Documentation writers Bilde av Particularly helpful Moodlers Bilde av Peer reviewers Bilde av Plugin developers
Note that once you upgrade to Moodle 1.9, this will become a configuration setting.

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.
Som svar til Tim Hunt

Re: How do we install this?

av Samuli Karevaara -
It's probably a global setting? Haven't had the chance to try it out yet. I'd like to have a theme-based setting for that. Maybe it's an easy hack in 1.9, I'll take a peek next year smiler
Som svar til Tim Hunt

Re: How do we install this?

av David Mudrák -
Bilde av Core developers Bilde av Documentation writers Bilde av Moodle HQ Bilde av Particularly helpful Moodlers Bilde av Peer reviewers Bilde av Plugin developers Bilde av Plugins guardians Bilde av Testers Bilde av Translators
Hi there,

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?
Som svar til David Mudrák

Re: How do we install this?

av Tim Hunt -
Bilde av Core developers Bilde av Documentation writers Bilde av Particularly helpful Moodlers Bilde av Peer reviewers Bilde av Plugin developers
The OpenLearn people implemented categories in the breadcrumb trail as a local hack. In build_navigation, after:
 // 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.
Som svar til Tim Hunt

categories in the breadcrumb

av Peter Birdsall -

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

Gjennomsnittlig vurdering:Useful (1)
Som svar til Peter Birdsall

Re: categories in the breadcrumb

av Tim Hunt -
Bilde av Core developers Bilde av Documentation writers Bilde av Particularly helpful Moodlers Bilde av Peer reviewers Bilde av Plugin developers
Build_navigation is probably the 'right' place to implement this.

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.
Som svar til Tim Hunt

Re: categories in the breadcrumb

av Martín Langhoff -
I use grep all the time blunker - Normally I do 'grep on\ dostuff'. The 'on' catches the end of the 'function' definition. Works great

Some editors have support for the tabs file. I've failed to get my emacs to play with it properly though blandet
Som svar til Martín Langhoff

Re: categories in the breadcrumb

av David Mudrák -
Bilde av Core developers Bilde av Documentation writers Bilde av Moodle HQ Bilde av Particularly helpful Moodlers Bilde av Peer reviewers Bilde av Plugin developers Bilde av Plugins guardians Bilde av Testers Bilde av Translators
> Some editors have support for the tabs file

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 tongueout
Som svar til Tim Hunt

Re: How do we install this?

av Mich P -
Tim, you mentioned that once you upgrade to Moodle 1.9, this will become a configuration setting. Can you tell me which setting this is as I haven't seen it?