Skip to content

Commit

Permalink
Merge pull request #6084 from samvera/5586-deposit-new-work-through-c…
Browse files Browse the repository at this point in the history
…ollection

Valkyrie: populate correct collection when depositing new works through collection
  • Loading branch information
alishaevn authored Jun 26, 2023
2 parents afa8aba + ef0087e commit 611c351
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/helpers/hyrax/membership_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,30 @@ module MembershipHelper
#
# @see app/assets/javascripts/hyrax/relationships.js
def member_of_collections_json(resource)
# this is where we return for dassie
return resource.member_of_collections_json if
resource.respond_to?(:member_of_collections_json)

resource = resource.model if resource.respond_to?(:model)

Hyrax.custom_queries.find_collections_for(resource: resource).map do |collection|
existing_collections_array = Hyrax.custom_queries.find_collections_for(resource: resource) + add_collection_from_params
existing_collections_array.map do |collection|
{ id: collection.id.to_s,
label: collection.title.first,
path: url_for(collection) }
end.to_json
end

def add_collection_from_params
# avoid errors when creating Valkyrie resources from Dashboard >> Works
return [] if controller.params[:add_works_to_collection].blank?

# new valkyrie works need the collection from params when depositing directly into an existing collection
return [Hyrax.metadata_adapter.query_service.find_by(id: Valkyrie::ID.new(controller.params[:add_works_to_collection]))] if Hyrax.config.use_valkyrie?

[::Collection.find(@controller.params[:add_works_to_collection])]
end

##
# @param resource [#work_members_json]
#
Expand Down

0 comments on commit 611c351

Please sign in to comment.