diff --git a/app/controllers/homepage_controller.rb b/app/controllers/homepage_controller.rb index 009228e145..93bc536eff 100644 --- a/app/controllers/homepage_controller.rb +++ b/app/controllers/homepage_controller.rb @@ -18,10 +18,6 @@ def search_component end helper_method :search_component - def publication_class - HomepagePresenter - end - def show_search_autocomplete? true unless ENV["GOVUK_DISABLE_SEARCH_AUTOCOMPLETE"] end diff --git a/app/models/content_item.rb b/app/models/content_item.rb index 202ef8e6be..8fd1851c31 100644 --- a/app/models/content_item.rb +++ b/app/models/content_item.rb @@ -3,9 +3,9 @@ class ContentItem include Withdrawable - attr_reader :attachments, :content_store_response, :content_store_hash, :body, :image, - :description, :document_type, :schema_name, :title, :base_path, :locale, - :public_updated_at + attr_reader :attachments, :base_path, :body, :content_store_hash, + :content_store_response, :description, :document_type, :image, + :links, :locale, :public_updated_at, :schema_name, :title # SCAFFOLDING: remove the override_content_store_hash parameter when full landing page # content items including block details are available from content-store @@ -22,6 +22,7 @@ def initialize(content_store_response, override_content_store_hash: nil) @base_path = content_store_hash["base_path"] @locale = content_store_hash["locale"] @public_updated_at = content_store_hash["public_updated_at"] + @links = content_store_hash["links"] @attachments = get_attachments(content_store_hash.dig("details", "attachments")) diff --git a/app/models/homepage.rb b/app/models/homepage.rb new file mode 100644 index 0000000000..6a47d63f64 --- /dev/null +++ b/app/models/homepage.rb @@ -0,0 +1,11 @@ +class Homepage < ContentItem + def popular_links + @popular_links ||= popular_links_data&.collect(&:with_indifferent_access) + end + +private + + def popular_links_data + @popular_links_data ||= links.dig("popular_links", 0, "details", "link_items") + end +end diff --git a/app/presenters/homepage_presenter.rb b/app/presenters/homepage_presenter.rb deleted file mode 100644 index 840bfd5bb1..0000000000 --- a/app/presenters/homepage_presenter.rb +++ /dev/null @@ -1,27 +0,0 @@ -class HomepagePresenter < ContentItemPresenter - PASS_THROUGH_KEYS = %i[ - links - ].freeze - - PASS_THROUGH_KEYS.each do |key| - define_method key do - content_item[key.to_s] - end - end - - def link_items - @link_items ||= links.dig("popular_links", 0, "details", "link_items") - end - - def hardcoded_popular_links - @hardcoded_popular_links ||= I18n.t("homepage.index.popular_links") - end - - def popular_links_data - link_items || hardcoded_popular_links - end - - def popular_links - @popular_links ||= popular_links_data.collect(&:with_indifferent_access) - end -end diff --git a/app/views/homepage/_popular_links.html.erb b/app/views/homepage/_popular_links.html.erb index 128e82439f..c93db948d6 100644 --- a/app/views/homepage/_popular_links.html.erb +++ b/app/views/homepage/_popular_links.html.erb @@ -1,7 +1,6 @@ <% add_view_stylesheet("popular_links") %> -