diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 1ed94ddc..774790ec 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -27,7 +27,7 @@ def current_year
def text_area?(field, exhibit)
index_field_config = exhibit.blacklight_config.index_fields[field.field]
- index_field_config.text_area == "1"
+ index_field_config&.text_area == "1"
end
def text_area_value(field, sidecar)
diff --git a/app/presenters/rtl_index_presenter.rb b/app/presenters/rtl_index_presenter.rb
index 669ead8a..27fb1c61 100644
--- a/app/presenters/rtl_index_presenter.rb
+++ b/app/presenters/rtl_index_presenter.rb
@@ -26,13 +26,22 @@ def value_from_symbol(field)
default_title_field = @configuration.index.title_field.to_sym
display_title_field = @configuration.index.display_title_field.to_sym
+ # When asked for a title, display the override title if it's present.
if field == default_title_field && @document.key?(display_title_field)
- @document[display_title_field]
+ @document[override_title_field] || @document[display_title_field]
else
@document[field]
end
end
+ def exhibit_prefix
+ @exhibit_prefix ||= configuration.facet_fields["exhibit_tags"].field.gsub("tags_ssim", "")
+ end
+
+ def override_title_field
+ :"#{exhibit_prefix}override-title_ssim"
+ end
+
def label_value(value, config)
if value.is_a?(Array) && value.count > 1
value.collect { |v| field_values(config, value: v.html_safe) }
diff --git a/app/presenters/rtl_show_presenter.rb b/app/presenters/rtl_show_presenter.rb
index a0bdf88a..0d1a3b14 100644
--- a/app/presenters/rtl_show_presenter.rb
+++ b/app/presenters/rtl_show_presenter.rb
@@ -25,7 +25,7 @@ def field_value(field, options = {})
end
def header
- fields = Array.wrap(view_config.title_field)
+ fields = Array.wrap(title_field)
f = fields.detect { |field| @document.has? field }
f ||= @configuration.document_model.unique_key
@document[f].to_sentence(field_config(f).separator_options)
@@ -33,12 +33,29 @@ def header
end
def heading
- fields = Array.wrap(view_config.title_field)
+ fields = Array.wrap(title_field)
f = fields.detect { |field| document.has? field }
f ||= configuration.document_model.unique_key
field_values(field_config(f), value: document[f].map(&:html_safe))
end
+ # Automatically display the override title if it's present.
+ def title_field
+ if @document.has?(override_title_field) && @document[override_title_field].present?
+ override_title_field
+ else
+ view_config.title_field
+ end
+ end
+
+ def exhibit_prefix
+ @exhibit_prefix ||= configuration.facet_fields["exhibit_tags"].field.gsub("tags_ssim", "")
+ end
+
+ def override_title_field
+ :"#{exhibit_prefix}override-title_ssim"
+ end
+
def html_title
super.split("
").map(&:html_safe).join(", ")
end
diff --git a/app/services/iiif_manifest.rb b/app/services/iiif_manifest.rb
index 8bbcdab9..e9043bbb 100644
--- a/app/services/iiif_manifest.rb
+++ b/app/services/iiif_manifest.rb
@@ -61,6 +61,7 @@ def noid
def manifest_metadata
metadata = metadata_class.new(manifest).to_solr
return {} if metadata.blank?
+ metadata = default_metadata(metadata).merge(metadata)
create_sidecars_for(*metadata.keys)
metadata.each_with_object({}) do |(key, value), hash|
@@ -71,10 +72,27 @@ def manifest_metadata
end
end
+ # When importing a IIIF Resource the first time, create an "Override Title" field.
+ def default_metadata(metadata)
+ return {} if metadata["Title"].blank?
+ {
+ "Override Title" => nil
+ }
+ end
+
def create_sidecars_for(*keys)
missing_keys(keys).each do |k|
- exhibit.custom_fields.create! label: k, readonly_field: true, field_type: "vocab"
+ readonly = k != "Override Title"
+ field = exhibit.custom_fields.create! label: k, readonly_field: readonly, field_type: "vocab"
+ field.update(configuration: field.configuration.merge("if" => false)) if disabled_fields.include?(k)
end
@exhibit_custom_fields = nil
end
+
+ def disabled_fields
+ [
+ "Override Title",
+ "Title"
+ ]
+ end
end
diff --git a/app/values/manifest_metadata.rb b/app/values/manifest_metadata.rb
index 134776d0..8392409a 100644
--- a/app/values/manifest_metadata.rb
+++ b/app/values/manifest_metadata.rb
@@ -65,6 +65,7 @@ def language_name(value)
ISO_639.find_by_code(value).try(:english_name) || value
end
end
+
def process_values(input_hash)
h = Hash[input_hash.map do |key, values|
Value.new(key, values).to_pair
diff --git a/app/views/spotlight/catalog/_edit_default.html.erb b/app/views/spotlight/catalog/_edit_default.html.erb
index 969e1926..cba236ea 100644
--- a/app/views/spotlight/catalog/_edit_default.html.erb
+++ b/app/views/spotlight/catalog/_edit_default.html.erb
@@ -25,7 +25,8 @@
<% else %>
<%= d.text_field_without_bootstrap field.field, value: document.sidecar(current_exhibit).data[field.field.to_s], class: 'form-control', readonly: field.readonly_field? %>
<% end %>
- <% unless field.configured_to_display? %>
+ <%# Don't show a warning for the override title - it should never display in the show fields. %>
+ <% unless field.slug == "override-title_ssim" || field.configured_to_display? %>
<%= t(:'.blank_field_warning_html', link: link_to(t(:'spotlight.configuration.sidebar.metadata'), spotlight.edit_exhibit_metadata_configuration_path(current_exhibit))) %> diff --git a/config/initializers/monkeypatches/spotlight_breadcrumb_patch.rb b/config/initializers/monkeypatches/spotlight_breadcrumb_patch.rb new file mode 100644 index 00000000..3d69572e --- /dev/null +++ b/config/initializers/monkeypatches/spotlight_breadcrumb_patch.rb @@ -0,0 +1,18 @@ +Rails.application.config.to_prepare do + module SpotlightBreadcrumbPatch + def add_document_breadcrumbs(document) + if current_browse_category + add_breadcrumb current_browse_category.exhibit.main_navigations.browse.label_or_default, exhibit_browse_index_path(current_browse_category.exhibit) + add_breadcrumb current_browse_category.title, exhibit_browse_path(current_browse_category.exhibit, current_browse_category) + elsif current_page_context && current_page_context.title.present? && !current_page_context.is_a?(Spotlight::HomePage) + add_breadcrumb current_page_context.title, [current_page_context.exhibit, current_page_context] + elsif current_search_session + add_breadcrumb t(:'spotlight.catalog.breadcrumb.index'), search_action_url(current_search_session.query_params) + end + + add_breadcrumb RTLShowPresenter.new(document, self).html_title, polymorphic_path([current_exhibit, document]) + end + end + + Spotlight::CatalogController.prepend(SpotlightBreadcrumbPatch) +end diff --git a/spec/presenters/rtl_index_presenter_spec.rb b/spec/presenters/rtl_index_presenter_spec.rb index 79a28585..21fb6528 100644 --- a/spec/presenters/rtl_index_presenter_spec.rb +++ b/spec/presenters/rtl_index_presenter_spec.rb @@ -16,7 +16,8 @@ let(:blacklight_config) do double( index: index_config, - index_fields: { field: field_config } + index_fields: { field: field_config }, + facet_fields: { "exhibit_tags" => double(field: "tags_ssim") } ) end @@ -55,6 +56,21 @@ end end + context 'when an override field exists' do + let(:index_config) { double(title_field: 'title', display_title_field: 'alternate_title') } + let(:document) do + { + title: title, + alternate_title: alternate_title, + "override-title_ssim": ["Test"] + } + end + + it 'renders it' do + expect(presenter.label(:title)).to eq "Test" + end + end + context 'when passed a string' do it 'renders the string as the label' do label_value = 'a string' diff --git a/spec/presenters/rtl_show_presenter_spec.rb b/spec/presenters/rtl_show_presenter_spec.rb index bbe0f3cd..acd67da8 100644 --- a/spec/presenters/rtl_show_presenter_spec.rb +++ b/spec/presenters/rtl_show_presenter_spec.rb @@ -15,7 +15,8 @@ double( show_fields: { field: double(highlight: false, accessor: nil, default: nil, field: :field, text_area: false, helper_method: nil, link_to_search: nil, itemprop: nil, separator_options: nil, :separator_options= => nil) }, - view_config: double(title_field: :title, html_title_field: nil) + view_config: double(title_field: :title, html_title_field: nil), + facet_fields: { "exhibit_tags" => double(field: "tags_ssim") } ) end @@ -36,11 +37,39 @@ it "returns multiple titles appropriately" do expect(presenter.header).to eq "