Allow removing Help from the menu #1020

Open
JorisDebonnet opened this Issue May 27, 2014 · 10 comments

Projects

None yet

6 participants

@JorisDebonnet

See also this forum post from 5 years ago:
http://www.silverstripe.org/general-questions/show/6930#post260666

Apparently, the Help link is added near the end of execution, causing the following to fail in _config.php:

CMSMenu::remove_menu_item('Help');

While that does work on ReportAdmin and even CMSSettingsController. I suppose moving the addition of that menu item to the same place as where CMSSettingsController is added, should fix it.

@stevie-mayhew

You can decorate LeftAndMain to perform this if necessary:

<?php
class LeftAndMainDecorator extends Extension
{
    public function onAfterInit() {
            CMSMenu::remove_menu_item('Help');
    }
}
---
Name: remove-help
After: 'framework/*','cms/*'
---
LeftAndMain:
  extensions:
    - LeftAndMainDecorator
@JorisDebonnet

Indeed, I also found that workaround in the post I linked, but I see that I forgot to mention that here.

Is it inconvenient then to make CMSMenu::remove_menu_item work in _config.php for this case, by moving up the addition of that menu item?

@nimeso

+1 to fix this :)

@JorisDebonnet

I checked how the menu is populated to see why the Help item is different from the others.

The menu items are all added in framework/admin/code/LeftAndMain.php. Most of them are added in the function MainMenu (items received from CMSMenu::get_viewable_menu_items(), processed, and saved as an ArrayList into $this->_cache_MainMenu). But the Help item is added separately in the init function, perhaps because it uses $this->config()->help_link, and saved directly with CMSMenu::add_link (so not through that _cache_MainMenu variable).

Perhaps the Help item could be moved from init to MainMenu without trouble, but it's in a different format, so it needs some rewriting (if at all possible). It doesn't work when I simply move that CMSMenu::add_link call between those functions: the Help item doesn't appear then.

@chillu
SilverStripe Ltd. member

We could avoid adding it if the help_link is set to null, which you can do through the YAML config? There's some older discussion around the CMSMenu API in silverstripe/silverstripe-framework#2673 which might provide some context. The GroupedCMSMenu implementation makes the menu a lot simpler to specify and customise, but has the disadvantage that there's no auto-adding of new ModelAdmin classes.

@stevie-mayhew

We use the GroupedCMSMenu for everything, its a really handy addition to the CMS interface for organisation but I think its good as a module, not part of core.

I've just tried setting the help_link to null and it doesn't seem to work in 3.1.8 at all - the current link remains. Same with false values (silverstripe/silverstripe-framework#3272 and silverstripe/silverstripe-framework#3275)

@chillu
SilverStripe Ltd. member

Yeah I'm not saying null does work, but we could make it work

@jonom

@JorisDebonnet do you know if this is still an issue? Would you like to open a PR to implement @chillu's suggestion?

@tractorcow

Yes please... otherwise we might have to close this if no one is willing to implement this.

@JorisDebonnet

I'll try to check this in the weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment