Skip to content

Commit

Permalink
Do not run menu config in after_initialize
Browse files Browse the repository at this point in the history
In order to prevent ordering issues we simply
do that in normal init flow.
  • Loading branch information
tvdeyen committed Oct 25, 2023
1 parent 5a94369 commit b16121f
Showing 1 changed file with 61 additions and 62 deletions.
123 changes: 61 additions & 62 deletions config/initializers/spree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,67 @@
Spree.user_class = "Alchemy::User"
end

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: "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
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"
)
end
config.menu_items << alchemy_menu_item
end

if config.menu_items.any? { |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`.")
else
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
end

0 comments on commit b16121f

Please sign in to comment.