Class: Fields::BlockList

Inherits:
Field
  • Object
show all
Defined in:
app/models/iron/fields/block_list.rb

Instance Method Summary collapse

Instance Method Details

#content_value=(value) ⇒ Object



12
13
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
41
# File 'app/models/iron/fields/block_list.rb', line 12

def content_value=(value)
  @content_errors = nil

  if value.nil?
    blocks.each(&:mark_for_destruction)
    return
  end

  unless value.is_a?(Array)
    add_content_error("must be an array")
    return
  end

  blocks.each(&:mark_for_destruction)

  value.each_with_index do |block_data, index|
    block_def = resolve_block_definition(block_data)
    next unless block_def

    block = blocks.build(entry: entry, definition: block_def, rank: index)

    block_def.field_definitions.each do |nested_def|
      raw = Field.content_fetch(block_data, nested_def.handle)
      next if raw == CONTENT_MISSING

      field = block.fields.build(type: nested_def.field_type, entry: entry, definition: nested_def)
      field.content_value = raw
    end
  end
end

#export_attachmentsObject



51
52
53
# File 'app/models/iron/fields/block_list.rb', line 51

def export_attachments
  blocks.flat_map(&:export_attachments)
end

#export_valueObject



47
48
49
# File 'app/models/iron/fields/block_list.rb', line 47

def export_value
  { type: "block_list", value: blocks.map(&:export_value) }
end

#valueObject



43
44
45
# File 'app/models/iron/fields/block_list.rb', line 43

def value
  blocks.map(&:value)
end