Skip to content

Commit

Permalink
Update menu item config for Solidus 4.2
Browse files Browse the repository at this point in the history
1. Run the config in after initialize, so we make sure the menu has been setup by the main app correctly
2. We use the new remix icons if the new admin menu is used.
3. We add our menu tab above the settings icon.
  • Loading branch information
tvdeyen committed Nov 9, 2023
1 parent 01f88dd commit b7c6304
Showing 1 changed file with 61 additions and 58 deletions.
119 changes: 61 additions & 58 deletions config/initializers/spree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,69 @@
Spree.user_class = "Alchemy::User"
end

Spree::Backend::Config.configure do |config|
alchemy_menu_item = if Spree.solidus_gem_version >= Gem::Version.new("4.2.0")
config.class::MenuItem.new(
label: :cms,
icon: "copy",
condition: -> { can?(:index, :alchemy_admin_dashboard) },
url: -> { Alchemy::Engine.routes.url_helpers.admin_dashboard_path },
children: [
config.class::MenuItem.new(
label: :pages,
condition: -> { can?(:index, :alchemy_admin_pages) },
url: -> { Alchemy::Engine.routes.url_helpers.admin_pages_path },
match_path: "/pages"
),
config.class::MenuItem.new(
label: :languages,
condition: -> { can?(:index, :alchemy_admin_sites) },
url: -> { Alchemy::Engine.routes.url_helpers.admin_sites_path },
match_path: "/languages"
),
(if defined?(Alchemy::Devise::Engine)
config.class::MenuItem.new(
label: :users,
condition: -> { can?(:index, :alchemy_admin_users) },
url: -> { Alchemy::Engine.routes.url_helpers.admin_users_path },
match_path: "/users"
)
end),
config.class::MenuItem.new(
label: :tags,
condition: -> { can?(:index, :alchemy_admin_tags) },
url: -> { Alchemy::Engine.routes.url_helpers.admin_tags_path }
),
config.class::MenuItem.new(
label: :pictures,
condition: -> { can?(:index, :alchemy_admin_pictures) },
url: -> { Alchemy::Engine.routes.url_helpers.admin_pictures_path }
),
config.class::MenuItem.new(
label: :attachments,
condition: -> { can?(:index, :alchemy_admin_attachments) },
url: -> { Alchemy::Engine.routes.url_helpers.admin_attachments_path }
)
].compact
)
else
config.class::MenuItem.new(
[:pages, :sites, :languages, :tags, :users, :pictures, :attachments],
"copy",
label: :cms,
condition: -> { can?(:index, :alchemy_admin_dashboard) },
partial: "spree/admin/shared/alchemy_sub_menu",
url: "/admin/pages",
match_path: "/pages"
)
Rails.application.config.after_initialize do
Spree::Backend::Config.configure do |config|
alchemy_menu_item = if Spree.solidus_gem_version >= Gem::Version.new("4.2.0")
config.class::MenuItem.new(
label: :cms,
icon: config.admin_updated_navbar ? "ri-pages-line" : "copy",
condition: -> { can?(:index, :alchemy_admin_dashboard) },
url: -> { Alchemy::Engine.routes.url_helpers.admin_dashboard_path },
children: [
config.class::MenuItem.new(
label: :pages,
condition: -> { can?(:index, :alchemy_admin_pages) },
url: -> { Alchemy::Engine.routes.url_helpers.admin_pages_path },
match_path: "/pages"
),
config.class::MenuItem.new(
label: :languages,
condition: -> { can?(:index, :alchemy_admin_sites) },
url: -> { Alchemy::Engine.routes.url_helpers.admin_sites_path },
match_path: "/languages"
),
(if defined?(Alchemy::Devise::Engine)
config.class::MenuItem.new(
label: :users,
condition: -> { can?(:index, :alchemy_admin_users) },
url: -> { Alchemy::Engine.routes.url_helpers.admin_users_path },
match_path: "/users"
)
end),
config.class::MenuItem.new(
label: :tags,
condition: -> { can?(:index, :alchemy_admin_tags) },
url: -> { Alchemy::Engine.routes.url_helpers.admin_tags_path }
),
config.class::MenuItem.new(
label: :pictures,
condition: -> { can?(:index, :alchemy_admin_pictures) },
url: -> { Alchemy::Engine.routes.url_helpers.admin_pictures_path }
),
config.class::MenuItem.new(
label: :attachments,
condition: -> { can?(:index, :alchemy_admin_attachments) },
url: -> { Alchemy::Engine.routes.url_helpers.admin_attachments_path }
)
].compact
)
else
config.class::MenuItem.new(
[:pages, :sites, :languages, :tags, :users, :pictures, :attachments],
"copy",
label: :cms,
condition: -> { can?(:index, :alchemy_admin_dashboard) },
partial: "spree/admin/shared/alchemy_sub_menu",
url: "/admin/pages",
match_path: "/pages"
)
end
settings = config.menu_items.detect { |item| item.label == :settings }
config.menu_items.index(settings).tap do |index|
config.menu_items.insert(index, alchemy_menu_item)
end
end
config.menu_items << alchemy_menu_item
end

Rails.application.config.after_initialize do
if Spree::Backend::Config.menu_items.many? { |menu_item| menu_item.label == :cms }
Alchemy::Deprecation.warn("You configured the Alchemy menu items in your app's initializers. We can do that for you now! Please remove the menu item with the label `:cms`.")
end
Expand Down

0 comments on commit b7c6304

Please sign in to comment.