Sha256: c750dd48bf337428781c61d43b2d89805bd4210b49426be5e4758b9349bede19

Contents?: true

Size: 868 Bytes

Versions: 12

Compression:

Stored size: 868 Bytes

Contents

module Hyrax
  module ParentContainer
    extend ActiveSupport::Concern

    included do
      helper_method :parent
    end

    # TODO: this is slow, refactor to return a Presenter (fetch from solr)
    def parent
      @parent ||= new_or_create? ? find_parent_by_id : lookup_parent_from_child
    end

    def find_parent_by_id
      ActiveFedora::Base.find(parent_id)
    end

    def lookup_parent_from_child
      # in_objects method is inherited from Hydra::PCDM::ObjectBehavior
      return curation_concern.in_objects.first if curation_concern
      return ParentService.parent_for(@presenter.id) if @presenter
      raise "no child"
    end

    def parent_id
      @parent_id ||= new_or_create? ? params[:parent_id] : lookup_parent_from_child.id
    end

    private

      def new_or_create?
        %w[create new].include? action_name
      end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
hyrax-2.0.3 app/controllers/concerns/hyrax/parent_container.rb
hyrax-2.0.2 app/controllers/concerns/hyrax/parent_container.rb
hyrax-2.0.1 app/controllers/concerns/hyrax/parent_container.rb
hyrax-2.0.0 app/controllers/concerns/hyrax/parent_container.rb
hyrax-2.0.0.rc3 app/controllers/concerns/hyrax/parent_container.rb
hyrax-2.0.0.rc2 app/controllers/concerns/hyrax/parent_container.rb
hyrax-2.0.0.rc1 app/controllers/concerns/hyrax/parent_container.rb
hyrax-2.0.0.beta5 app/controllers/concerns/hyrax/parent_container.rb
hyrax-2.0.0.beta4 app/controllers/concerns/hyrax/parent_container.rb
hyrax-2.0.0.beta3 app/controllers/concerns/hyrax/parent_container.rb
hyrax-2.0.0.beta2 app/controllers/concerns/hyrax/parent_container.rb
hyrax-2.0.0.beta1 app/controllers/concerns/hyrax/parent_container.rb