1+ require 'deprecation'
12module Blacklight ::UrlHelperBehavior
3+ extend Deprecation
4+ self . deprecation_horizon = 'blacklight 6.0'
25
36 ##
47 # Extension point for downstream applications
5- # to provide more interesting routing to
8+ # to provide more interesting routing to
69 # documents
710 def url_for_document doc
8- doc
11+ if controller . is_a? Blacklight ::Catalog and doc . is_a? SolrDocument and
12+ ( !doc . respond_to? ( :to_model ) or doc . to_model . is_a? SolrDocument )
13+ { controller : controller_name , action : :show , id : doc }
14+ else
15+ doc
16+ end
917 end
1018
1119 # link_to_document(doc, :label=>'VIEW', :counter => 3)
@@ -15,30 +23,55 @@ def url_for_document doc
1523 def link_to_document ( doc , opts = { :label => nil , :counter => nil } )
1624 opts [ :label ] ||= document_show_link_field ( doc )
1725 label = render_document_index_label doc , opts
18- link_to label , url_for_document ( doc ) , search_session_params ( opts [ :counter ] ) . merge ( opts . reject { | k , v | [ :label , :counter ] . include? k } )
26+ link_to label , url_for_document ( doc ) , document_link_params ( doc , opts )
1927 end
2028
29+ def document_link_params ( doc , opts )
30+ session_tracking_params ( doc , opts [ :counter ] ) . merge ( opts . reject { |k , v | [ :label , :counter ] . include? k } )
31+ end
32+ protected :document_link_params
33+
2134 ##
2235 # Link to the previous document in the current search context
2336 def link_to_previous_document ( previous_document )
24- link_to_unless previous_document . nil? , raw ( t ( 'views.pagination.previous' ) ) , url_for_document ( previous_document ) , search_session_params ( search_session [ 'counter' ] . to_i - 1 ) . merge ( :class => "previous" , :rel => 'prev' ) do
37+ link_opts = session_tracking_params ( previous_document , search_session [ 'counter' ] . to_i - 1 ) . merge ( :class => "previous" , :rel => 'prev' )
38+ link_to_unless previous_document . nil? , raw ( t ( 'views.pagination.previous' ) ) , url_for_document ( previous_document ) , link_opts do
2539 content_tag :span , raw ( t ( 'views.pagination.previous' ) ) , :class => 'previous'
2640 end
2741 end
2842
2943 ##
3044 # Link to the next document in the current search context
3145 def link_to_next_document ( next_document )
32- link_to_unless next_document . nil? , raw ( t ( 'views.pagination.next' ) ) , url_for_document ( next_document ) , search_session_params ( search_session [ 'counter' ] . to_i + 1 ) . merge ( :class => "next" , :rel => 'next' ) do
46+ link_opts = session_tracking_params ( next_document , search_session [ 'counter' ] . to_i + 1 ) . merge ( :class => "next" , :rel => 'next' )
47+ link_to_unless next_document . nil? , raw ( t ( 'views.pagination.next' ) ) , url_for_document ( next_document ) , link_opts do
3348 content_tag :span , raw ( t ( 'views.pagination.next' ) ) , :class => 'next'
3449 end
3550 end
3651
3752 ##
3853 # Current search context parameters
39- def search_session_params counter
54+ def search_session_params counter
4055 { :'data-counter' => counter , :'data-search_id' => current_search_session . try ( :id ) }
4156 end
57+ deprecation_deprecate :search_session_params
58+
59+ ##
60+ # Attributes for a link that gives a URL we can use to track clicks for the current search session
61+ # @param [SolrDocument] document
62+ # @param [Integer] counter
63+ # @example
64+ # session_tracking_params(SolrDocument.new(id: 123), 7)
65+ # => { data: { :'tracker-href' => '/catalog/123/track?counter=7&search_id=999' } }
66+ def session_tracking_params document , counter
67+ if document . nil?
68+ return { }
69+ end
70+
71+ { :data => { :'context-href' => track_solr_document_path ( document , counter : counter , search_id : current_search_session . try ( :id ) ) } }
72+ end
73+ protected :session_tracking_params
74+
4275
4376 #
4477 # link based helpers ->
0 commit comments