From 326576ecb20fe033d777f7c3276e533744825609 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Thu, 21 Sep 2023 10:25:09 -0700 Subject: [PATCH] add missing methods to avoid content block errors --- .../hyrax/homepage_controller_decorator.rb | 20 +++++++++++++++++++ app/models/content_block.rb | 20 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 app/controllers/hyrax/homepage_controller_decorator.rb diff --git a/app/controllers/hyrax/homepage_controller_decorator.rb b/app/controllers/hyrax/homepage_controller_decorator.rb new file mode 100644 index 000000000..826a8599b --- /dev/null +++ b/app/controllers/hyrax/homepage_controller_decorator.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +# OVERRIDE Hyrax 3.5 to add content blocks +module Hyrax + module HomepageControllerDecorator + + def index + @presenter = presenter_class.new(current_ability, collections) + @featured_researcher = ContentBlock.for(:researcher) + @marketing_text = ContentBlock.for(:marketing) + @featured_work_list = FeaturedWorkList.new + @announcement_text = ContentBlock.for(:announcement) + @homepage_about_section_heading = ContentBlock.for(:homepage_about_section_heading) + @homepage_about_section_content = ContentBlock.for(:homepage_about_section_content) + recent + end + end +end + +Hyrax::HomepageController.prepend Hyrax::HomepageControllerDecorator diff --git a/app/models/content_block.rb b/app/models/content_block.rb index c9e72b26e..4c00535b3 100644 --- a/app/models/content_block.rb +++ b/app/models/content_block.rb @@ -16,7 +16,9 @@ class ContentBlock < ApplicationRecord help: :help_page, terms: :terms_page, agreement: :agreement_page, - home_text: :home_text + home_text: :home_text, + homepage_about_section_heading: :homepage_about_section_heading, + homepage_about_section_content: :homepage_about_section_content }.freeze # NOTE: method defined outside the metaclass wrapper below because @@ -90,6 +92,22 @@ def home_text=(value) home_text.update(value: value) end + def homepage_about_section_heading + find_or_create_by(name: 'homepage_about_section_heading') + end + + def homepage_about_section_heading=(value) + homepage_about_section_heading.update(value: value) + end + + def homepage_about_section_content + find_or_create_by(name: 'homepage_about_section_content') + end + + def homepage_about_section_content=(value) + homepage_about_section_content.update(value: value) + end + def about_page find_or_create_by(name: 'about_page') end