Module: Hyrax::AttributesHelper
- Included in:
- HyraxHelperBehavior
- Defined in:
- app/helpers/hyrax/attributes_helper.rb
Instance Method Summary collapse
-
#conform_field(field_name, options_hash) ⇒ String
The field name to be used for rendering.
-
#conform_options(field_name, view_options) ⇒ Hash
The transformed options for the field.
-
#schema(model) ⇒ Hash
The schema for the model or nil if not found.
- #view_options_for(presenter) ⇒ Object
- #view_options_without_flexibility(presenter, model_name) ⇒ Object
Instance Method Details
#conform_field(field_name, options_hash) ⇒ String
Returns the field name to be used for rendering.
62 63 64 |
# File 'app/helpers/hyrax/attributes_helper.rb', line 62 def conform_field(field_name, ) &.with_indifferent_access&.fetch('render_term', nil) || field_name end |
#conform_options(field_name, view_options) ⇒ Hash
Returns the transformed options for the field.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/helpers/hyrax/attributes_helper.rb', line 70 def (field_name, ) hash_of_locales = .delete(:display_label) || {} if hash_of_locales.present? [:label] = hash_of_locales[locale] || hash_of_locales[:default] else [:label] = ([:render_term] || field_name).to_s end field = [:label] translate = I18n.t(field, default: field) if field.match(/\./) if translate && translate != field [:label] = translate else [:label] = field_label( :"blacklight.search.fields.index.#{field}", :"blacklight.search.fields.show.#{field}", :"blacklight.search.fields.#{field}", field.to_s.humanize ) end end |
#schema(model) ⇒ Hash
Returns the schema for the model or nil if not found.
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/helpers/hyrax/attributes_helper.rb', line 44 def schema(model) return nil unless model.present? # If this is an ActiveFedoraDummyModel, get the schema from the actual model class if model.is_a?(Hyrax::ActiveFedoraDummyModel) actual_model = model.instance_variable_get(:@model) return schema(actual_model) if actual_model end # using respond_to? check because try? does not succeed with Dry::Types object that is returned by schema method return nil unless model.respond_to?(:schema) model.schema end |
#view_options_for(presenter) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'app/helpers/hyrax/attributes_helper.rb', line 5 def (presenter) model_name = presenter.model.model_name.name if presenter.respond_to?(:flexible?) && presenter.flexible? Hyrax::Schema.m3_schema_loader.view_definitions_for(schema: model_name, version: presenter.solr_document.schema_version, contexts: presenter.solr_document.contexts) else (presenter, model_name) end end |
#view_options_without_flexibility(presenter, model_name) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/helpers/hyrax/attributes_helper.rb', line 14 def (presenter, model_name) model = presenter.model schema = schema(model) # no schema found for given model - try a few more fallbacks # if wings is enabled we may be able to use the model registry to find the new model if schema.nil? && !Hyrax.config.disable_wings new_model = Wings::ModelRegistry.reverse_lookup(model) schema = schema(new_model) if new_model end # Check if the model has a resource version if schema.nil? new_model = "#{model_name}Resource".safe_constantize schema = schema(new_model) if new_model end # If we still don't have a schema, assume we have a pre-valkyrie model if schema.nil? if model.respond_to?(:local_attributes) return model.local_attributes else return [] end end Hyrax::Schema.simple_schema_loader.view_definitions_for(schema:) end |