Skip to content

Commit

Permalink
Override Blacklight's document_presenter to allow us to pass in the c…
Browse files Browse the repository at this point in the history
…ontextual view_config.
  • Loading branch information
cbeer committed Oct 25, 2024
1 parent d67f52d commit 4c804bf
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<% if body.present? %>
<%= body %>
<% elsif embed? %>
<%= embed %>
<% elsif partials? %>
<% partials.each do |partial| %>
<%= partial %>
<% end %>
<% elsif embed? %>
<%= embed %>
<% elsif thumbnail? %>
<%= thumbnail %>
<% end %>
5 changes: 5 additions & 0 deletions app/helpers/spotlight/main_app_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def link_back_to_catalog(opts = { label: nil })
super
end

# Expecting to upstream this override in https://github.com/projectblacklight/blacklight/pull/3343/files
def document_presenter(document, view_config: nil, **kwargs)
(view_config&.document_presenter_class || document_presenter_class(document)).new(document, self, view_config: view_config, **kwargs)
end

def document_presenter_class(_document)
if action_name == 'index'
super
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="box" data-id="<%= document.id %>">
<% view_config = blacklight_config.view_config(:embed) %>
<%= render (view_config.document_component || Spotlight::SolrDocumentLegacyEmbedComponent).new((Blacklight.version > '8.0' ? :document : :presenter) => document_presenter(document), counter: nil, block: local_assigns[:block]) do |component| %>
<%= render (view_config.document_component || Spotlight::SolrDocumentLegacyEmbedComponent).new((Blacklight.version > '8.0' ? :document : :presenter) => document_presenter(document, view_config: view_config), counter: nil, block: local_assigns[:block]) do |component| %>
<% component.with_partial do %>
<%= render_document_partials document, view_config.partials, component: component, document_counter: nil, view_config: view_config, block: local_assigns[:block], **(view_config.locals) %>
<% end if view_config&.partials&.any? %>
Expand Down
2 changes: 1 addition & 1 deletion blacklight-spotlight.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ these collections.)
s.add_dependency 'activejob-status'
s.add_dependency 'acts-as-taggable-on', '>= 5.0', '< 12'
s.add_dependency 'autoprefixer-rails'
s.add_dependency 'blacklight', '>= 7.19', '< 9'
s.add_dependency 'blacklight', '>= 7.40', '< 9'
s.add_dependency 'blacklight-gallery', '>= 3.0', '< 5'
s.add_dependency 'bootstrap_form', '>= 4.1', '< 6'
s.add_dependency 'cancancan'
Expand Down

0 comments on commit 4c804bf

Please sign in to comment.