Class: Hyrax::Forms::ResourceForm
- Defined in:
- app/forms/hyrax/forms/resource_form.rb
Overview
This form wraps Hyrax::ChangeSet
in the HydraEditor::Form
interface.
Direct Known Subclasses
Constant Summary collapse
- InWorksPrepopulator =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
proc do || self.in_works_ids = if persisted? Hyrax.query_service .find_inverse_references_by(resource: model, property: :member_ids) .select(&:work?) .map(&:id) else [] end end
- LockKeyPrepopulator =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Note:includes special handling for Wings, to support compatibility with ‘etag`-driven, application-side lock checks. for non-wings adapters we want to move away from application side lock validation and rely on the adapter/database features instead.
proc do || if Hyrax.config.disable_wings || !Hyrax..is_a?(Wings::Valkyrie::MetadataAdapter) Hyrax.logger.info "trying to prepopulate a lock token for " \ "#{self.class.inspect}, but optimistic locking isn't " \ "supported for the configured adapter: #{Hyrax..class}" self.version = '' else self.version = model.persisted? ? Wings::ActiveFedoraConverter.convert(resource: model).etag : '' end end
Class Method Summary collapse
-
.for(resource) ⇒ Object
Factory for generic, per-work froms.
-
.required_fields ⇒ Array<Symbol>
List of required field names as symbols.
-
.required_fields=(fields) ⇒ Array<Symbol>
List of required field names as symbols.
Instance Method Summary collapse
-
#[]=(attr, value) ⇒ Object
The set value.
-
#display_additional_fields? ⇒ Boolean
Whether there are terms to display ‘below-the-fold’.
-
#model_class ⇒ Class
deprecated
Deprecated.
use model.class instead
-
#primary_terms ⇒ Array<Symbol>
Terms for display ‘above-the-fold’, or in the most prominent form real estate.
-
#secondary_terms ⇒ Array<Symbol>
Terms for display ‘below-the-fold’.
Class Method Details
.for(resource) ⇒ Object
Factory for generic, per-work froms
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/forms/hyrax/forms/resource_form.rb', line 123 def for(resource) "#{resource.class.name}Form".constantize.new(resource) rescue NameError => _err case resource when Hyrax::AdministrativeSet Hyrax::Forms::AdministrativeSetForm.new(resource) when Hyrax::FileSet Hyrax::Forms::FileSetForm.new(resource) when Hyrax::PcdmCollection Hyrax::Forms::PcdmCollectionForm.new(resource) else # NOTE: This will create a +Hyrax::Forms::PcdmObjectForm+. Hyrax::Forms::ResourceForm(resource.class).new(resource) end end |
.required_fields ⇒ Array<Symbol>
Returns list of required field names as symbols.
141 142 143 144 145 |
# File 'app/forms/hyrax/forms/resource_form.rb', line 141 def required_fields definitions .select { |_, definition| definition[:required] } .keys.map(&:to_sym) end |
.required_fields=(fields) ⇒ Array<Symbol>
Returns list of required field names as symbols.
151 152 153 154 155 156 157 158 |
# File 'app/forms/hyrax/forms/resource_form.rb', line 151 def required_fields=(fields) fields = fields.map(&:to_s) raise(KeyError) unless fields.all? { |f| definitions.key?(f) } fields.each { |field| definitions[field].merge!(required: true) } required_fields end |
Instance Method Details
#[]=(attr, value) ⇒ Object
Returns the set value.
166 167 168 |
# File 'app/forms/hyrax/forms/resource_form.rb', line 166 def []=(attr, value) public_send("#{attr}=".to_sym, value) end |
#display_additional_fields? ⇒ Boolean
Returns whether there are terms to display ‘below-the-fold’.
197 198 199 |
# File 'app/forms/hyrax/forms/resource_form.rb', line 197 def display_additional_fields? secondary_terms.any? end |
#model_class ⇒ Class
use model.class instead
174 175 176 |
# File 'app/forms/hyrax/forms/resource_form.rb', line 174 def model_class # rubocop:disable Rails/Delegate model.class end |
#primary_terms ⇒ Array<Symbol>
Returns terms for display ‘above-the-fold’, or in the most prominent form real estate.
181 182 183 184 185 |
# File 'app/forms/hyrax/forms/resource_form.rb', line 181 def primary_terms _form_field_definitions .select { |_, definition| definition[:primary] } .keys.map(&:to_sym) end |
#secondary_terms ⇒ Array<Symbol>
Returns terms for display ‘below-the-fold’.
189 190 191 192 193 |
# File 'app/forms/hyrax/forms/resource_form.rb', line 189 def secondary_terms _form_field_definitions .select { |_, definition| definition[:display] && !definition[:primary] } .keys.map(&:to_sym) end |