Class: Fields::ReferenceList
- Inherits:
-
Field
- Object
- Field
- Fields::ReferenceList
- Defined in:
- app/models/iron/fields/reference_list.rb
Instance Method Summary collapse
Instance Method Details
#content_value=(value) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/models/iron/fields/reference_list.rb', line 8 def content_value=(value) @content_errors = nil references.each(&:mark_for_destruction) Array(value).each_with_index do |entry_id, index| referenced = Entry.find_by(id: entry_id) if referenced.nil? add_content_error("contains a reference to a non-existing entry") elsif !supported_content_type?(referenced) add_content_error("contains a reference to an unsupported content type") else references.build(entry_id: entry_id, rank: index) end end end |
#export_value ⇒ Object
34 35 36 |
# File 'app/models/iron/fields/reference_list.rb', line 34 def export_value { type: "reference_list", value: references.map(&:entry_id) } end |
#value ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'app/models/iron/fields/reference_list.rb', line 25 def value references.map do |reference| OpenStruct.new( id: reference.entry_id, _type: reference.entry.content_type.handle ) end end |