Modifying standard navigation block links?

Modifying standard navigation block links?

by tim st.clair -
Number of replies: 5
Picture of Plugin developers

A client of mine asked if they could turn OFF the "my home" button, and the "site pages" button. I wasn't able to see a setting for it (e.g. not documented at http://docs.moodle.org/22/en/Navigation that it is possible) so I looked into the code.

I had to modify the /moodle/blocks/navigation/ block. This is of course not ideal, and was wondering what the correct way to perform this would be instead?

E.g to add the option to the settings form I had to modify the specific_definition inside block_navigation_edit_form class to modify

    $mods = array('enabledock'=>'yes', 'linkcategories'=>'no', 'showmyhome'=>'yes');

then within the rendere:

    } else if ($item->action instanceof moodle_url) {
        if ($item->action == new moodle_url('/my/') && $options['showmyhome']=='no') {
            continue;
        } else {
            $content = html_writer::link($item->action, $content, $attributes);
        }

I basically want to have a plugin (say, in /local/) that can just modify the global $navigation for the rootnodes ['site'] & ['home'] but I can't figure out how to do that.

Average of ratings: -
In reply to tim st.clair

Vastus: Modifying standard navigation block links?

by Tõnis Tartes -
Picture of Core developers Picture of Plugin developers Picture of Testers Picture of Translators

I would not recommend you to hack the core code. Instead, try overriding renderers in your selected theme(or multiple themes). You should read this - http://docs.moodle.org/dev/Themes_2.0_overriding_a_renderer#Overriding_a_component.27s_renderer

If you hack the core code, you might get into trouble updating your moodle later.

In reply to Tõnis Tartes

Re: Vastus: Modifying standard navigation block links?

by tim st.clair -
Picture of Plugin developers

yep, I realise that I shouldn't modify the core code. my question was how to remove items from the NAVIGATION core block that appear to be hard coded in (such as my home). I wasn't able to follow the documentation to work out how to iterate and remove standard items from the global navigation for the navigation block - can add to it easy enough, but removing is not the same.

In reply to tim st.clair

Re: Vastus: Modifying standard navigation block links?

by K P -

Hi there... Is there any update for this? Thanks smile

In reply to K P

Re: Vastus: Modifying standard navigation block links?

by tim st.clair -
Picture of Plugin developers

Ooh, searched and found my thread I'd forgotten about. In the end I didn't modify the navigation block at all - I used CSS to hide stuff instead. problems with screen readers but the client I did this for wasn't worrying about that. Here's the low down - plonk one of these styles (or all) into your theme css to "remove" items from the nav bar.

/* Remove "my home" */

.block_navigation .type_setting.depth_2 { display: none; }

/* Remove "site pages" */
.block_navigation .type_course.depth_2 { display: none; }

/* Remove "My Profile" */
.block_navigation .type_user.depth_2 { display: none; }

/* Remove "Profile settings (user edit, etc without removing the capability)"
#settingsnav .block_tree li.type_unknown { display: none; } */

/* Remove "Courses"
.block_navigation .type_system.depth_2 { display: none; } */

Average of ratings: Useful (1)
In reply to tim st.clair

Re: Vastus: Modifying standard navigation block links?

by Bob Conner -

Hi Tim,

I would like to expand on the code you provided above to remove other navigation items, for example everything to do with Badges.  While studying your code I cannot figure out how to modify it to do this.  Can you provide a further explanation on exactly how this code works. 

 I think I  understand that the the /*Remove "My home" */ are comments.

Also, I think in understand that {display: none; } prevents the navigation item from displaying.

What I cannot seem to figure out is  when you removed Site Pages, how did you know that .block_navigation .type_user.depth_2 was the correct code to make Site Pages disappear.

Also, how would I figure out what code to use to remove the entire Badges section?

I am using version 2.9.2.

Thank you in advance for your help.

Bob