Adding a admin interface menu item in Solidus, shows up before user logged in

363 views Asked by At

This is documented in the customization documents. But if you add a menu item in this way, it will show up as a link even when a user has not yet logged into the admin area.

1

There are 1 answers

0
Cody On

In the MenuItem docs you'll find some additional settings not listed in the example, the one we're concerned with is 'condition'. If this returns true the item will show up.

Here's an example that works that I used to create an 'analytics' button.

Spree::Backend::Config.configure do |config|
  config.menu_items << config.class::MenuItem.new(
    [:analytics],
    'line-chart',
    url: '#',
    condition: -> { can?(:manage, Spree::Order) }
  )
end

It should also be noted that Solidus seems to currently only support font-awesome icons up to version 4.7? So, I thought about using the abacus here for fun, and because the app I'm working on is a Japanese app so it's culturally communicative--but that is not available in version 4.

I looked around and couldn't find this information so I thought I'd share it here for anyone searching. Hope it helps!

EDIT:

I also had an issue with i18n local filtering and using the string url pattern here. The way the link is actually constructed on the admin -> sidebar -> menu -> tabs partial can be found here.

If a symbol is provided instead of a string, it is sent as a public send to the spree app. The existing menu items are here for reference.