Class: ModsDisplay::NestedRelatedItem

Inherits:
Field
  • Object
show all
Includes:
RelatedItemConcerns
Defined in:
lib/mods_display/fields/nested_related_item.rb

Overview

This class will hopefully take over for related item support more broadly. Currently there is behavior in RelatedItem and Collection that would need to be accounted for when adding nested metadata support.

Instance Method Summary collapse

Methods inherited from Field

#initialize, #label, #render_in

Constructor Details

This class inherits a constructor from ModsDisplay::Field

Instance Method Details

#fieldsObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mods_display/fields/nested_related_item.rb', line 11

def fields
  @fields ||= begin
    return_fields = @values.map do |value|
      next if related_item_is_a_collection?(value)
      next unless render_nested_related_item?(value)

      related_item_mods_object(value)
    end.compact
    collapse_fields(return_fields)
  end
end

#to_html(view_context = ApplicationController.renderer) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mods_display/fields/nested_related_item.rb', line 23

def to_html(view_context = ApplicationController.renderer)
  helpers = view_context.respond_to?(:simple_format) ? view_context : ApplicationController.new.view_context

  component = ModsDisplay::ListFieldComponent.with_collection(
    fields,
    value_transformer: ->(value) { helpers.format_mods_html(value.to_s) },
    list_html_attributes: { class: 'mods_display_nested_related_items' },
    list_item_html_attributes: { class: 'mods_display_nested_related_item open' }
  )

  view_context.render component, layout: false
end