Class: Hyrax::Forms::PcdmCollectionForm

Inherits:
ResourceForm show all
Defined in:
app/forms/hyrax/forms/pcdm_collection_form.rb

Overview

Constant Summary collapse

BannerInfoPrepopulator =
lambda do |**_options|
  self.banner_info ||= begin
    banner_info = CollectionBrandingInfo.where(collection_id: id.to_s, role: "banner")
    banner_file = File.split(banner_info.first.local_path).last unless banner_info.empty?
    alttext = banner_info.first.alt_text unless banner_info.empty?
    file_location = banner_info.first.local_path unless banner_info.empty?
    relative_path = "/" + banner_info.first.local_path.split("/")[-4..-1].join("/") unless banner_info.empty?
    { file: banner_file, full_path: file_location, relative_path: relative_path, alttext: alttext }
  end
end
LogoInfoPrepopulator =
lambda do |**_options|
  self.logo_info ||= begin
    logos_info = CollectionBrandingInfo.where(collection_id: id.to_s, role: "logo")

    logos_info.map do |logo_info|
      logo_file = File.split(logo_info.local_path).last
      relative_path = "/" + logo_info.local_path.split("/")[-4..-1].join("/")
      alttext = logo_info.alt_text
      linkurl = logo_info.target_url
      { file: logo_file, full_path: logo_info.local_path, relative_path: relative_path, alttext: alttext, linkurl: linkurl }
    end
  end
end

Constants inherited from ResourceForm

ResourceForm::LockKeyPrepopulator

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ResourceForm

#[]=, for, #initialize, #model_class, required_fields=

Methods inherited from ChangeSet

for

Constructor Details

This class inherits a constructor from Hyrax::Forms::ResourceForm

Class Method Details

.model_classObject



48
49
50
# File 'app/forms/hyrax/forms/pcdm_collection_form.rb', line 48

def model_class
  Hyrax::PcdmCollection
end

.required_fieldsArray<Symbol>

Returns list of required field names as symbols.

Returns:

  • (Array<Symbol>)

    list of required field names as symbols



54
55
56
57
58
# File 'app/forms/hyrax/forms/pcdm_collection_form.rb', line 54

def required_fields
  definitions
    .select { |_, definition| definition[:required] }
    .keys.map(&:to_sym)
end

Instance Method Details

#display_additional_fields?Boolean

Returns whether there are terms to display ‘below-the-fold’.

Returns:

  • (Boolean)

    whether there are terms to display ‘below-the-fold’



80
81
82
# File 'app/forms/hyrax/forms/pcdm_collection_form.rb', line 80

def display_additional_fields?
  secondary_terms.any?
end

#primary_termsArray<Symbol>

Returns terms for display ‘above-the-fold’, or in the most prominent form real estate.

Returns:

  • (Array<Symbol>)

    terms for display ‘above-the-fold’, or in the most prominent form real estate



64
65
66
67
68
# File 'app/forms/hyrax/forms/pcdm_collection_form.rb', line 64

def primary_terms
  _form_field_definitions
    .select { |_, definition| definition[:primary] }
    .keys.map(&:to_sym)
end

#secondary_termsArray<Symbol>

Returns terms for display ‘below-the-fold’.

Returns:

  • (Array<Symbol>)

    terms for display ‘below-the-fold’



72
73
74
75
76
# File 'app/forms/hyrax/forms/pcdm_collection_form.rb', line 72

def secondary_terms
  _form_field_definitions
    .select { |_, definition| definition[:display] && !definition[:primary] }
    .keys.map(&:to_sym)
end