Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Solidus Alchemy menu items in initializer #98

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions config/initializers/spree.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,68 @@
if defined?(Alchemy::Devise::Engine)
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"
)
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
end
21 changes: 0 additions & 21 deletions lib/generators/alchemy/solidus/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,6 @@ def run_spree_custom_user_generator
end
end

def inject_admin_tab
inject_into_file "config/initializers/spree.rb",
{
after:
"Spree::Backend::Config.configure do |config|\n"
} do
<<~ADMIN_TAB
\ # AlchemyCMS admin tabs
\ config.menu_items << 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'
\ )
ADMIN_TAB
end
end

def create_admin_user
if alchemy_devise_present? && !options[:skip_alchemy_user_generator] &&
Alchemy::User.count.zero?
Expand Down