diff --git a/app/models/alchemy/page.rb b/app/models/alchemy/page.rb index e860fa4ebb..e55ac491f5 100644 --- a/app/models/alchemy/page.rb +++ b/app/models/alchemy/page.rb @@ -138,9 +138,6 @@ class Page < BaseRecord after_update :create_legacy_url, if: :saved_change_to_urlname? - after_update :attach_to_menu!, - if: :should_attach_to_menu? - after_update -> { nodes.update_all(updated_at: Time.current) } # Concerns @@ -152,8 +149,6 @@ class Page < BaseRecord # site_name accessor delegate :name, to: :site, prefix: true, allow_nil: true - attr_accessor :menu_id - # Class methods # class << self @@ -545,18 +540,5 @@ def create_legacy_url def set_published_at self.published_at = Time.current end - - def attach_to_menu! - node = Alchemy::Node.find_by!(id: menu_id, language_id: language_id) - node.children.create!( - language_id: language_id, - page_id: id, - name: name, - ) - end - - def should_attach_to_menu? - menu_id.present? && nodes.none? - end end end diff --git a/app/views/alchemy/admin/pages/_form.html.erb b/app/views/alchemy/admin/pages/_form.html.erb index c48717284e..9ab4448f16 100644 --- a/app/views/alchemy/admin/pages/_form.html.erb +++ b/app/views/alchemy/admin/pages/_form.html.erb @@ -10,7 +10,7 @@
<%= render 'alchemy/admin/pages/publication_fields' %> <%= page_status_checkbox(@page, :restricted) %> - <%= render 'alchemy/admin/pages/menu_fields', f: f %> + <%= page_status_checkbox(@page, :visible) %> <% if configuration(:sitemap)['show_flag'] %> <%= page_status_checkbox(@page, :sitemap) %> <% end %> diff --git a/app/views/alchemy/admin/pages/_menu_fields.html.erb b/app/views/alchemy/admin/pages/_menu_fields.html.erb deleted file mode 100644 index dadb0f2641..0000000000 --- a/app/views/alchemy/admin/pages/_menu_fields.html.erb +++ /dev/null @@ -1,33 +0,0 @@ -<% if @page.menus.any? %> - - <% @page.menus.each do |menu| %> - - <%= menu.name %> - - <% end %> -<% elsif Alchemy::Node.roots.any? %> - <%= page_status_checkbox(@page, :visible) %> - <%= f.input :menu_id, collection: Alchemy::Node.roots.map { |n| [n.name, n.id] }, - prompt: Alchemy.t('Please choose a menu'), - input_html: { class: 'alchemy_selectbox' }, - wrapper_html: { style: @page.visible? ? 'display: block' : 'display: none' }, - label: false %> - -<% else %> - <%= page_status_checkbox(@page, :visible) %> -<% end %> diff --git a/spec/models/alchemy/page_spec.rb b/spec/models/alchemy/page_spec.rb index 9a64a09223..9c96ece5e1 100644 --- a/spec/models/alchemy/page_spec.rb +++ b/spec/models/alchemy/page_spec.rb @@ -1991,45 +1991,6 @@ module Alchemy end end - describe "#attach_to_menu!" do - let(:page) { create(:alchemy_page) } - - context "if menu_id is set" do - let(:root_node) { create(:alchemy_node) } - - before do - page.menu_id = root_node.id - end - - context "and no nodes are present yet" do - it "attaches to menu" do - expect { page.save }.to change { page.nodes.count }.from(0).to(1) - end - end - - context "and nodes are already present" do - let!(:page_node) { create(:alchemy_node, page: page) } - - it "does not attach to menu" do - expect { page.save }.not_to change { page.nodes.count } - end - end - end - - context "if menu_id is not set" do - it "does not attach to menu" do - expect { page.save }.not_to change { page.nodes.count } - end - end - - context "if menu_id is empty" do - it "does not raise error" do - page.menu_id = "" - expect { page.save }.not_to raise_error - end - end - end - describe "#nodes" do let(:page) { create(:alchemy_page) } let(:node) { create(:alchemy_node, page: page, updated_at: 1.hour.ago) }