diff --git a/app/controllers/hyku_knapsack/note_form_behavior.rb b/app/controllers/hyku_knapsack/note_form_behavior.rb new file mode 100644 index 0000000..bac00b1 --- /dev/null +++ b/app/controllers/hyku_knapsack/note_form_behavior.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module HykuKnapsack + module NoteFormBehavior + extend ActiveSupport::Concern + + included do + self.terms += [:note] + + delegate :note, to: :model + end + + class_methods do + def build_permitted_params + super.tap { |permitted_params| permitted_params << [:note] } + end + end + end +end diff --git a/app/forms/hyrax/una_open_educational_resource_form.rb b/app/forms/hyrax/una_open_educational_resource_form.rb index f91d39b..1f8255d 100644 --- a/app/forms/hyrax/una_open_educational_resource_form.rb +++ b/app/forms/hyrax/una_open_educational_resource_form.rb @@ -3,7 +3,7 @@ module Hyrax class UnaOpenEducationalResourceForm < Hyrax::Forms::WorkForm include Hyrax::DOI::DataCiteDOIFormBehavior - include HykuKnapsack::WorkForm + include Hyku::Plugin::Schema::Yaml::WorkForm include Hyku::Plugin::Schema::Yaml::Hyrax::FormFields(:una_open_educational_resource) self.model_class = ::UnaOpenEducationalResource diff --git a/app/presenters/concerns/hyku_knapsack/person_or_organization_presenter_behavior.rb b/app/presenters/concerns/hyku_knapsack/person_or_organization_presenter_behavior.rb index 03b8f7d..de6ac4d 100644 --- a/app/presenters/concerns/hyku_knapsack/person_or_organization_presenter_behavior.rb +++ b/app/presenters/concerns/hyku_knapsack/person_or_organization_presenter_behavior.rb @@ -15,7 +15,7 @@ def contributor_list # TODO: Add view_context and use link_to and image_tag instead of <%== in the view # TODO: Need to normalize ids in the work model in order for these methods to work in all cases (and stay simple) class PersonOrOrganization < Struct.new(:display_name, :orcid, :isni, :ror, :grid, :wikidata) - include Hyrax::Orcid::OrcidHelper + #include Hyrax::Orcid::OrcidHelper def orcid_url "https://orcid.org/#{validate_orcid(orcid)}" if orcid.present? diff --git a/app/presenters/concerns/hyku_knapsack/presenter_delegatable.rb b/app/presenters/concerns/hyku_knapsack/presenter_delegatable.rb new file mode 100644 index 0000000..a6ef10a --- /dev/null +++ b/app/presenters/concerns/hyku_knapsack/presenter_delegatable.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module HykuKnapsack + module PresenterDelegatable + extend ActiveSupport::Concern + + def self.delegated_methods + raise NotImplementedError, "delegated_methods must return an array of method names" + end + + included do + # Check if any other concerns have registered methods before delegating, which prevents + # concerns like Hyrax::DOI::DOIPresenterBehavior trying to register a helper `doi` method + # which is not called, as we already delegated the method and it could not be overwritten. + delegated_methods.each { |method| delegate(method, to: :solr_document) unless instance_methods.include?(method) } + + # NOTE: + # I hate this being here, and wonder if it wouldn't be better to just include it on every + # presenter than needs to delegate isbn? + alias_method :isbns, :isbn if respond_to?(:delegated_methods) && delegated_methods.include?(:isbn) + end + end +end