app/forms/hyrax/scholarly_work_form.rb
# frozen_string_literal: true
# Generated via
# `rails generate hyrax:work ScholarlyWork`
module Hyrax
class ScholarlyWorkForm < ::SingleValueForm
class_attribute :single_value_fields
self.model_class = ::ScholarlyWork
self.terms += [:resource_type, :admin_note, :advisor, :conference_name, :date_issued, :dcmi_type,
:digital_collection, :doi, :deposit_agreement, :agreement, :note]
self.terms -= [:bibliographic_citation, :contributor, :publisher, :related_url, :source, :date_created]
self.required_fields = [:title, :creator, :abstract, :date_issued]
self.single_value_fields = [:title, :license]
self.admin_only_terms += [:description, :digital_collection]
self.default_term_values = { dcmi_type: ['http://purl.org/dc/dcmitype/Text'],
rights_statement: 'http://rightsstatements.org/vocab/InC/1.0/',
language: ['http://id.loc.gov/vocabulary/iso639-2/eng'] }
# Add overrides for required properties which are becoming single-valued
def title
super.first || ''
end
def license
super.first || ''
end
delegate :advisors_attributes=, to: :model
delegate :creators_attributes=, to: :model
def advisors
model.advisors.build if model.advisors.blank?
model.advisors.to_a
end
def creators
model.creators.build if model.creators.blank?
model.creators.to_a
end
def self.build_permitted_params
permitted = super
permitted << { advisors_attributes: [:id, :index, :name, :affiliation, :orcid, :other_affiliation, :_destroy] }
permitted << { creators_attributes: [:id, :index, :name, :affiliation, :orcid, :other_affiliation, :_destroy] }
permitted
end
end
end