From 2b4a9e3afc0b2c6ca571f984e3010869e716b2a8 Mon Sep 17 00:00:00 2001 From: William Dewey Date: Fri, 4 Oct 2024 13:27:24 -0500 Subject: [PATCH] restore bugfix for missing @page_facets fixes #305 Jessica previously fixed this bug but the fix wasn't applied to the new method --- app/helpers/orchid/facet_helper.rb | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/helpers/orchid/facet_helper.rb b/app/helpers/orchid/facet_helper.rb index 5fe1023..bca63a5 100644 --- a/app/helpers/orchid/facet_helper.rb +++ b/app/helpers/orchid/facet_helper.rb @@ -16,14 +16,21 @@ def create_label(key, default="No Label") # used for URL creation and translation matching # label: non normalized value ("Willa Cather", '"Yellowstone Kelly"') def facet_label(type: nil, normalized: nil, label: nil) - # determine if translation needed - info = @page_facets[type] - if info && info["flags"] && info["flags"].include?("translate") - # do not need "label" since that will be found in the locale info - facet_label_translation(type: type, normalized: normalized) + # if @page_facets are not present, for example if a search_preset + # view or a custom action are using the metadata method, + # do not error but just skip possible translations + if @page_facets.present? + # determine if translation needed + info = @page_facets[type] + if info && info["flags"] && info["flags"].include?("translate") + # do not need "label" since that will be found in the locale info + facet_label_translation(type: type, normalized: normalized) + else + # if there is no label specified, use the normalized version + sanitize(label) || normalized + end else - # if there is no label specified, use the normalized version - sanitize(label) || normalized + label end end