app/forms/hyrax/forms/collection_form.rb in hyrax-3.0.0.pre.rc1 vs app/forms/hyrax/forms/collection_form.rb in hyrax-3.0.0.pre.rc2
- old
+ new
@@ -1,15 +1,17 @@
+# frozen_string_literal: true
module Hyrax
module Forms
# rubocop:disable Metrics/ClassLength
class CollectionForm
include HydraEditor::Form
include HydraEditor::Form::Permissions
# Used by the search builder
attr_reader :scope
- delegate :id, :depositor, :permissions, :human_readable_type, :member_ids, :nestable?, :alt_title, to: :model
+ delegate :id, :depositor, :permissions, :human_readable_type, :member_ids, :nestable?,
+ :alternative_title, to: :model
class_attribute :membership_service_class
# Required for search builder (FIXME)
alias collection model
@@ -18,11 +20,11 @@
self.membership_service_class = Collections::CollectionMemberService
delegate :blacklight_config, to: Hyrax::CollectionsController
- self.terms = [:alt_title, :resource_type, :title, :creator, :contributor, :description,
+ self.terms = [:alternative_title, :resource_type, :title, :creator, :contributor, :description,
:keyword, :license, :publisher, :date_created, :subject, :language,
:representative_id, :thumbnail_id, :identifier, :based_near,
:related_url, :visibility, :collection_type_gid]
self.required_fields = [:title]
@@ -31,48 +33,18 @@
def can?(*args)
current_ability.can?(*args)
end
end
- # @param model [Collection] the collection model that backs this form
+ # @param model [::Collection] the collection model that backs this form
# @param current_ability [Ability] the capabilities of the current user
# @param repository [Blacklight::Solr::Repository] the solr repository
def initialize(model, current_ability, repository)
super(model)
@scope = ProxyScope.new(current_ability, repository, blacklight_config)
end
- # Cast back to multi-value when saving
- # Reads from form
- def self.model_attributes(attributes)
- attrs = super
- return attrs unless attributes[:title]
-
- attrs[:title] = Array(attributes[:title])
- return attrs if attributes[:alt_title].nil?
- Array(attributes[:alt_title]).each do |value|
- attrs["title"] << value if value != ""
- end
- attrs
- end
-
- # @param [Symbol] key the field to read
- # @return the value of the form field.
- # For display in edit page
- def [](key)
- return model.member_of_collection_ids if key == :member_of_collection_ids
- if key == :title
- @attributes["title"].each do |value|
- @attributes["alt_title"] << value
- end
- @attributes["alt_title"].delete(@attributes["alt_title"].sort.first) unless @attributes["alt_title"].empty?
- return @attributes["title"].sort.first unless @attributes["title"].empty?
- return ""
- end
- super
- end
-
def permission_template
@permission_template ||= begin
template_model = PermissionTemplate.find_or_create_by(source_id: model.id)
PermissionTemplateForm.new(template_model)
end
@@ -88,11 +60,11 @@
[:title, :description]
end
# Terms that appear within the accordion
def secondary_terms
- [:alt_title,
+ [:alternative_title,
:creator,
:contributor,
:keyword,
:license,
:publisher,
@@ -150,38 +122,38 @@
end
def available_parent_collections(scope:)
return @available_parents if @available_parents.present?
- collection = Collection.find(id)
+ collection = ::Collection.find(id)
colls = Hyrax::Collections::NestedCollectionQueryService.available_parent_collections(child: collection, scope: scope, limit_to_id: nil)
@available_parents = colls.map do |col|
{ "id" => col.id, "title_first" => col.title.first }
end
@available_parents.to_json
end
private
- def all_files_with_access
- member_presenters(member_work_ids).flat_map(&:file_set_presenters).map { |x| [x.to_s, x.id] }
- end
+ def all_files_with_access
+ member_presenters(member_work_ids).flat_map(&:file_set_presenters).map { |x| [x.to_s, x.id] }
+ end
- # Override this method if you have a different way of getting the member's ids
- def member_work_ids
- response = collection_member_service.available_member_work_ids.response
- response.fetch('docs').map { |doc| doc['id'] }
- end
+ # Override this method if you have a different way of getting the member's ids
+ def member_work_ids
+ response = collection_member_service.available_member_work_ids.response
+ response.fetch('docs').map { |doc| doc['id'] }
+ end
- def collection_member_service
- @collection_member_service ||= membership_service_class.new(scope: scope, collection: collection, params: blacklight_config.default_solr_params)
- end
+ def collection_member_service
+ @collection_member_service ||= membership_service_class.new(scope: scope, collection: collection, params: blacklight_config.default_solr_params)
+ end
- def member_presenters(member_ids)
- PresenterFactory.build_for(ids: member_ids,
- presenter_class: WorkShowPresenter,
- presenter_args: [nil])
- end
+ def member_presenters(member_ids)
+ PresenterFactory.build_for(ids: member_ids,
+ presenter_class: WorkShowPresenter,
+ presenter_args: [nil])
+ end
end
- # rubocop:enable ClassLength
+ # rubocop:enable Metrics/ClassLength
end
end