app/services/blacklight/field_retriever.rb in blacklight-7.11.1 vs app/services/blacklight/field_retriever.rb in blacklight-7.12.0

- old
+ new

@@ -1,17 +1,24 @@ # frozen_string_literal: true module Blacklight class FieldRetriever - # @param [SolrDocument] document + # @param [Blacklight::Document] document # @param [Blacklight::Configuration::Field] field_config solr field configuration - def initialize(document, field_config) + # @param [ActionView::Base] Rails rendering context + def initialize(document, field_config, view_context = nil) @document = document @field_config = field_config + @view_context = view_context end - attr_reader :document, :field_config + # @return [Blacklight::Document] + attr_reader :document + # @return [Blacklight::Configuration::Field] + attr_reader :field_config + # @return [ActionView::Base] + attr_reader :view_context delegate :field, to: :field_config # @return [Array] def fetch @@ -58,9 +65,16 @@ # retrieve the document value from the highlighting response document.highlight_field(field_config.field).map(&:html_safe) if document.has_highlight_field? field_config.field end def retrieve_values - field_config.values.call(field_config, document) + values_method = field_config.values + + if values_method.respond_to?(:arity) && values_method.arity.abs == 2 + Deprecation.warn(self, ":values parameter for field #{field_config.key} only accepts 2 arguments; should accept 3") + values_method.call(field_config, document) + else + values_method.call(field_config, document, view_context) + end end end end