Module: Hyrax::RedirectsFieldBehavior
- Included in:
- Forms::PcdmCollectionForm, Forms::PcdmObjectForm
- Defined in:
- app/forms/concerns/hyrax/redirects_field_behavior.rb
Overview
Form-side handling for the redirects nested-attribute field.
Submitted form payloads arrive under redirects_attributes and are
turned into plain hashes (the persisted shape — see
config/metadata/redirects.yaml, type: hash) by the populator.
The form partial wraps each persisted hash in a Hyrax::Redirect
value object at render time so the view can call .path and
.is_display_url.
The deserialize! override removes the renamed redirects key
before Reform's from_hash runs, so the form's redirects
property is written exclusively by the populator. See
Hyrax::BasedNearFieldBehavior for the parallel pattern.
Feature gating
self.included runs at class load time and uses the structural
gate Hyrax.config.redirects_enabled?. The runtime Flipflop
check isn't meaningful here because the form class is being
defined, not handling a request.
All runtime-side methods (deserialize!, populator) delegate to
Hyrax.config.redirects_active?, the two-gate combinator
(redirects_enabled? && Flipflop.redirects?). Calling
Flipflop.redirects? directly is unsafe when the config is off
because the feature isn't registered in that case.
Class Method Summary collapse
Instance Method Summary collapse
-
#deserialize!(params) ⇒ Object
Reform's FormBuilderMethods rewrites
redirects_attributes→redirectsbeforefrom_hashruns.
Class Method Details
.included(descendant) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'app/forms/concerns/hyrax/redirects_field_behavior.rb', line 31 def self.included(descendant) return unless Hyrax.config.redirects_enabled? # Declare the radio-group scalar before redirects_attributes so Reform # deserializes it first; the populator reads its value while building # per-row entries. descendant.property :redirects_display_url_index, virtual: true descendant.property :redirects_attributes, virtual: true, populator: :redirects_attributes_populator end |
Instance Method Details
#deserialize!(params) ⇒ Object
Reform's FormBuilderMethods rewrites redirects_attributes →
redirects before from_hash runs. Strip the renamed key so
the populator on redirects_attributes is the single entry
point for form-driven writes.
46 47 48 49 50 51 52 53 |
# File 'app/forms/concerns/hyrax/redirects_field_behavior.rb', line 46 def deserialize!(params) result = super if Hyrax.config.redirects_active? && result.respond_to?(:delete) result.delete('redirects') result.delete(:redirects) end result end |