diff --git a/app/helpers/blacklight/url_helper_behavior.rb b/app/helpers/blacklight/url_helper_behavior.rb index 6de8563ed0..5c5efe8768 100644 --- a/app/helpers/blacklight/url_helper_behavior.rb +++ b/app/helpers/blacklight/url_helper_behavior.rb @@ -12,14 +12,21 @@ def url_for_document(doc, options = {}) # so we only need the +counter+ param here. We also need to know if we are viewing to document as part of search results. # TODO: move this to the IndexPresenter def link_to_document(doc, field_or_opts = nil, opts = { counter: nil }) - if field_or_opts.is_a? Hash - opts = field_or_opts - else - field = field_or_opts - end + label = case field_or_opts + when NilClass + index_presenter(doc).label document_show_link_field(doc), opts + when Hash + opts = field_or_opts + index_presenter(doc).label document_show_link_field(doc), opts + when Proc, Symbol + Deprecation.warn(self, "passing a #{field_or_opts.class} to link_to_document is deprecated and will be removed in Blacklight 8") + Deprecation.silence(Blacklight::IndexPresenter) do + index_presenter(doc).label field_or_opts, opts + end + else # String + field_or_opts + end - field ||= document_show_link_field(doc) - label = index_presenter(doc).label field, opts link_to label, url_for_document(doc), document_link_params(doc, opts) end diff --git a/app/presenters/blacklight/index_presenter.rb b/app/presenters/blacklight/index_presenter.rb index 35effbfbbc..6776a47406 100644 --- a/app/presenters/blacklight/index_presenter.rb +++ b/app/presenters/blacklight/index_presenter.rb @@ -29,8 +29,12 @@ def label(field_or_string_or_proc, opts = {}) config = field_config(field_or_string_or_proc) document[field_or_string_or_proc] when Proc + Deprecation.warn(self, "calling IndexPresenter.label with a Proc is deprecated. " \ + "First argument must be a symbol. This will be removed in Blacklight 8") field_or_string_or_proc.call(document, opts) when String + Deprecation.warn(self, "calling IndexPresenter.label with a String is deprecated. " \ + "First argument must be a symbol. This will be removed in Blacklight 8") field_or_string_or_proc end diff --git a/spec/helpers/blacklight/url_helper_behavior_spec.rb b/spec/helpers/blacklight/url_helper_behavior_spec.rb index 8cc0462714..dae70c477a 100644 --- a/spec/helpers/blacklight/url_helper_behavior_spec.rb +++ b/spec/helpers/blacklight/url_helper_behavior_spec.rb @@ -204,6 +204,7 @@ end it "consists of the document title wrapped in a " do + expect(Deprecation).to receive(:warn) expect(helper.link_to_document(document, :title_tsim)).to have_selector("a", text: '654321', count: 1) end @@ -212,6 +213,7 @@ end it "accepts and returns a Proc" do + expect(Deprecation).to receive(:warn).twice expect(helper.link_to_document(document, proc { |doc, _opts| doc[:id] + ": " + doc.first(:title_tsim) })).to have_selector("a", text: '123456: 654321', count: 1) end @@ -219,10 +221,12 @@ let(:data) { { 'id' => id } } it "returns id" do + expect(Deprecation).to receive(:warn) expect(helper.link_to_document(document, :title_tsim)).to have_selector("a", text: '123456', count: 1) end it "is html safe" do + expect(Deprecation).to receive(:warn) expect(helper.link_to_document(document, :title_tsim)).to be_html_safe end @@ -245,7 +249,7 @@ it "converts the counter parameter into a data- attribute" do allow(helper).to receive(:track_test_path).with(hash_including(id: have_attributes(id: '123456'), counter: 5)).and_return('tracking url') - + expect(Deprecation).to receive(:warn) expect(helper.link_to_document(document, :title_tsim, counter: 5)).to include 'data-context-href="tracking url"' end