app/components/blacklight/document_metadata_component.rb in blacklight-7.16.0 vs app/components/blacklight/document_metadata_component.rb in blacklight-7.17.0
- old
+ new
@@ -1,18 +1,29 @@
# frozen_string_literal: true
module Blacklight
class DocumentMetadataComponent < ::ViewComponent::Base
+ renders_many :fields, (lambda do |component: nil, **kwargs|
+ (component || Blacklight::MetadataFieldComponent).new(**kwargs)
+ end)
with_collection_parameter :fields
# @param fields [Enumerable<Blacklight::FieldPresenter>] Document field presenters
- def initialize(fields:, show: false)
+ def initialize(fields: [], show: false)
@fields = fields
@show = show
end
+ def before_render
+ return unless fields
+
+ @fields.each do |field|
+ field(component: field_component(field), field: field, show: @show)
+ end
+ end
+
def render?
- @fields.any?
+ fields.present?
end
def field_component(field)
field&.component || Blacklight::MetadataFieldComponent
end