Skip to content

Commit

Permalink
Merge pull request #6395 from samvera/form_config
Browse files Browse the repository at this point in the history
Make form classes configurable
  • Loading branch information
dlpierce authored Oct 27, 2023
2 parents e6378d4 + 568db48 commit 5a8d0ee
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
9 changes: 4 additions & 5 deletions app/forms/hyrax/forms/resource_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ def self.ResourceForm(model_class)
@resource_forms ||= {}.compare_by_identity
@resource_forms[model_class] ||=
if model_class <= Hyrax::AdministrativeSet
Hyrax::Forms::AdministrativeSetForm
Hyrax.config.administrative_set_form
elsif model_class <= Hyrax::FileSet
Hyrax::Forms::FileSetForm
Hyrax.config.file_set_form
elsif model_class <= Hyrax::PcdmCollection
Hyrax::Forms::PcdmCollectionForm
Hyrax.config.pcdm_collection_form
else
"Hyrax::Forms::PcdmObjectForm".constantize # autoload
Hyrax::Forms::PcdmObjectForm(model_class)
Hyrax.config.pcdm_object_form_builder.call(model_class)
end
end

Expand Down
14 changes: 14 additions & 0 deletions lib/generators/hyrax/templates/config/initializers/hyrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,20 @@
# config.admin_set_model = 'AdminSet'
# config.admin_set_model = 'Hyrax::AdministrativeSet'

# Identify the form that will be used for Admin Sets
# config.administrative_set_form = Hyrax::Forms::AdministrativeSetForm

# Identify the form that will be used for File Sets
# config.file_set_form = Hyrax::Forms::FileSetForm

# Identify the form that will be used for Collections
# config.pcdm_collection_form = Hyrax::Forms::PcdmCollectionForm

# Provide a proc for form generation for Objects
# config.pcdm_object_form_builder = lambda do |model_class|
# Hyrax::Forms::PcdmObjectForm(model_class)
# end

# When your application is ready to use the valkyrie index instead of the one
# maintained by active fedora, you will need to set this to true. You will
# also need to update your Blacklight configuration.
Expand Down
31 changes: 31 additions & 0 deletions lib/hyrax/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,37 @@ def index_field_mapper
@index_field_mapper ||= ActiveFedora.index_field_mapper
end

attr_writer :administrative_set_form
##
# @return [Class]
def administrative_set_form
@administrative_set_model ||= Hyrax::Forms::AdministrativeSetForm
end

attr_writer :file_set_form
##
# @return [Class]
def file_set_form
@file_set_form ||= Hyrax::Forms::FileSetForm
end

attr_writer :pcdm_collection_form
##
# @return [Class]
def pcdm_collection_form
@pcdm_collection_form ||= Hyrax::Forms::PcdmCollectionForm
end

attr_writer :pcdm_object_form_builder
##
# @return [Proc]
def pcdm_object_form_builder
"Hyrax::Forms::PcdmObjectForm".constantize # autoload
@pcdm_object_form_builder = lambda do |model_class|
Hyrax::Forms::PcdmObjectForm(model_class)
end
end

# Should a button with "Share my work" show on the front page to users who are not logged in?
attr_writer :display_share_button_when_not_logged_in
def display_share_button_when_not_logged_in?
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/hyrax/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
it { is_expected.to respond_to(:admin_set_model=) }
it { is_expected.to respond_to(:admin_set_predicate) }
it { is_expected.to respond_to(:admin_set_predicate=) }
it { is_expected.to respond_to(:administrative_set_form) }
it { is_expected.to respond_to(:administrative_set_form=) }
it { is_expected.to respond_to(:analytic_start_date) }
it { is_expected.to respond_to(:analytics?) }
it { is_expected.to respond_to(:analytics_provider) }
Expand Down Expand Up @@ -51,6 +53,8 @@
it { is_expected.to respond_to(:enable_noids?) }
it { is_expected.to respond_to(:extract_full_text?) }
it { is_expected.to respond_to(:feature_config_path) }
it { is_expected.to respond_to(:file_set_form) }
it { is_expected.to respond_to(:file_set_form=) }
it { is_expected.to respond_to(:identifier_registrars) }
it { is_expected.to respond_to(:iiif_image_compliance_level_uri) }
it { is_expected.to respond_to(:iiif_image_compliance_level_uri=) }
Expand All @@ -75,6 +79,10 @@
it { is_expected.to respond_to(:max_days_between_fixity_checks=) }
it { is_expected.to respond_to(:max_notifications_for_dashboard) }
it { is_expected.to respond_to(:owner_permission_levels) }
it { is_expected.to respond_to(:pcdm_collection_form) }
it { is_expected.to respond_to(:pcdm_collection_form=) }
it { is_expected.to respond_to(:pcdm_object_form_builder) }
it { is_expected.to respond_to(:pcdm_object_form_builder=) }
it { is_expected.to respond_to(:permission_levels) }
it { is_expected.to respond_to(:permission_options) }
it { is_expected.to respond_to(:persistent_hostpath) }
Expand Down

0 comments on commit 5a8d0ee

Please sign in to comment.