diff --git a/lib/ProductOpener/APITest.pm b/lib/ProductOpener/APITest.pm
index 90193c79bf631..d75c69f290263 100644
--- a/lib/ProductOpener/APITest.pm
+++ b/lib/ProductOpener/APITest.pm
@@ -385,6 +385,7 @@ my $tests_ref = (
headers => {header1 => value1, } # optional. You may add an undef value to test for the inexistance of a header
response_content_must_match => "regexp" # optional. You may add a case insensitive regexp (e.g. "Product saved") that must be matched
response_content_must_not_match => "regexp" # optional. You may add a case insensitive regexp (e.g. "error") that must not be matched
+ sort_products_by => "product_name" # optional. You may provide a field to sort the returned products by so that they are in an expected order
}
],
);
@@ -565,6 +566,9 @@ sub execute_api_tests ($file, $tests_ref, $ua = undef) {
if (ref($decoded_json) eq 'HASH') {
if (defined $decoded_json->{'products'}) {
normalize_products_for_test_comparison($decoded_json->{'products'});
+ if (defined $test_ref->{sort_products_by}) {
+ sort_products_for_test_comparison($decoded_json->{'products'}, $test_ref->{sort_products_by});
+ }
}
if (defined $decoded_json->{'product'}) {
normalize_product_for_test_comparison($decoded_json->{'product'});
diff --git a/lib/ProductOpener/Display.pm b/lib/ProductOpener/Display.pm
index 9ef1789ad188c..da6ef84397c40 100644
--- a/lib/ProductOpener/Display.pm
+++ b/lib/ProductOpener/Display.pm
@@ -83,7 +83,6 @@ BEGIN {
&search_and_graph_products
&search_and_map_products
&display_recent_changes
- &add_tag_prefix_to_link
&display_taxonomy_api
&map_of_products
@@ -1525,6 +1524,8 @@ sub generate_query_cache_key ($name, $context_ref, $request_ref) {
sub query_list_of_tags ($request_ref, $query_ref) {
+ add_params_to_query($request_ref, $query_ref);
+
add_country_and_owner_filters_to_query($request_ref, $query_ref);
my $groupby_tagtype = $request_ref->{groupby_tagtype};
@@ -1827,33 +1828,14 @@ sub display_list_of_tags ($request_ref, $query_ref) {
. $th_nutriments
. "\n
\n";
- my $main_link = '';
+ # To get the root link, we remove the facet name from the current link
+ my $main_link = $request_ref->{current_link};
+ $main_link =~ s/\/[^\/]+$//; # Remove the last / and everything after ir
my $nofollow = '';
if (defined $request_ref->{tagid}) {
- local $log->context->{tagtype} = $request_ref->{tagtype};
- local $log->context->{tagid} = $request_ref->{tagid};
-
- $log->trace("determining main_link for the tag") if $log->is_trace();
- if (defined $taxonomy_fields{$request_ref->{tagtype}}) {
- $main_link = canonicalize_taxonomy_tag_link($lc, $request_ref->{tagtype}, $request_ref->{tagid});
- $log->debug("main_link determined from the taxonomy tag", {main_link => $main_link})
- if $log->is_debug();
- }
- else {
- $main_link = canonicalize_tag_link($request_ref->{tagtype}, $request_ref->{tagid});
- $log->debug("main_link determined from the canonical tag", {main_link => $main_link})
- if $log->is_debug();
- }
$nofollow = ' rel="nofollow"';
}
- # add back leading dash when a tag is excluded
- if ((defined $request_ref->{tag_prefix}) and ($request_ref->{tag_prefix} ne '')) {
- my $prefix = $request_ref->{tag_prefix};
- $main_link = add_tag_prefix_to_link($main_link, $prefix);
- $log->debug("Found tag prefix for main_link", {request => $request_ref}) if $log->is_debug();
- }
-
my %products = (); # number of products by tag, used for histogram of nutrition grades colors
$log->debug("going through all tags", {}) if $log->is_debug();
@@ -2044,7 +2026,7 @@ sub display_list_of_tags ($request_ref, $query_ref) {
}
}
- my $product_link = $main_link . $link;
+ my $tag_link = $main_link . $link;
$html .= "
\n";
my $tagentry = {
id => $tagid,
name => $display,
- url => $formatted_subdomain . $product_link,
+ url => $formatted_subdomain . $tag_link,
products => $products + 0, # + 0 to make the value numeric
known => $known, # 1 if the ingredient exists in the taxonomy, 0 if not
};
@@ -2156,7 +2138,7 @@ sub display_list_of_tags ($request_ref, $query_ref) {
# In case there are multiple country names and thus links that map to the region
# only keep the first one, which has the biggest count (and is likely to be the correct name)
if (not defined $countries_map_links->{$region}) {
- $countries_map_links->{$region} = $product_link;
+ $countries_map_links->{$region} = $tag_link;
my $name = $display;
$name =~ s/<(.*?)>//g;
$countries_map_names->{$region} = $name;
@@ -2883,8 +2865,8 @@ sub display_points ($request_ref) {
my $tagtype = $request_ref->{tagtype};
my $tagid = $request_ref->{tagid};
my $display_tag;
- my $newtagid;
- my $newtagidpath;
+ my $new_tagid;
+ my $new_tagid_path;
my $canon_tagid = undef;
local $log->context->{tagtype} = $tagtype;
@@ -2897,62 +2879,59 @@ sub display_points ($request_ref) {
$canon_tagid = canonicalize_taxonomy_tag($lc, $tagtype, $tagid);
$display_tag = display_taxonomy_tag($lc, $tagtype, $canon_tagid);
$title = $display_tag;
- $newtagid = get_taxonomyid($lc, $display_tag);
+ $new_tagid = get_taxonomyid($lc, $display_tag);
$log->debug("displaying points for a taxonomy tag",
- {canon_tagid => $canon_tagid, newtagid => $newtagid, title => $title})
+ {canon_tagid => $canon_tagid, new_tagid => $new_tagid, title => $title})
if $log->is_debug();
- if ($newtagid !~ /^(\w\w):/) {
- $newtagid = $lc . ':' . $newtagid;
+ if ($new_tagid !~ /^(\w\w):/) {
+ $new_tagid = $lc . ':' . $new_tagid;
}
- $newtagidpath = canonicalize_taxonomy_tag_link($lc, $tagtype, $newtagid);
- $request_ref->{current_link} = $newtagidpath;
+ $new_tagid_path = canonicalize_taxonomy_tag_link($lc, $tagtype, $new_tagid);
+ $request_ref->{current_link} = $new_tagid_path;
$request_ref->{world_current_link} = canonicalize_taxonomy_tag_link($lc, $tagtype, $canon_tagid);
}
else {
$display_tag = canonicalize_tag2($tagtype, $tagid);
- $newtagid = get_string_id_for_lang($lc, $display_tag);
+ $new_tagid = get_string_id_for_lang($lc, $display_tag);
$display_tag = display_tag_name($tagtype, $display_tag);
if ($tagtype eq 'emb_codes') {
- $canon_tagid = $newtagid;
+ $canon_tagid = $new_tagid;
$canon_tagid =~ s/-($ec_code_regexp)$/-ec/ie;
}
$title = $display_tag;
- $newtagidpath = canonicalize_tag_link($tagtype, $newtagid);
- $request_ref->{current_link} = $newtagidpath;
+ $new_tagid_path = canonicalize_tag_link($tagtype, $new_tagid);
+ $request_ref->{current_link} = $new_tagid_path;
my $current_lang = $lang;
my $current_lc = $lc;
$lang = 'en';
$lc = 'en';
- $request_ref->{world_current_link} = canonicalize_tag_link($tagtype, $newtagid);
+ $request_ref->{world_current_link} = canonicalize_tag_link($tagtype, $new_tagid);
$lang = $current_lang;
$lc = $current_lc;
$log->debug("displaying points for a normal tag",
- {canon_tagid => $canon_tagid, newtagid => $newtagid, title => $title})
+ {canon_tagid => $canon_tagid, new_tagid => $new_tagid, title => $title})
if $log->is_debug();
}
}
$request_ref->{current_link} .= "/points";
- if ((defined $tagid) and ($newtagid ne $tagid)) {
+ if ((defined $tagid) and ($new_tagid ne $tagid)) {
$request_ref->{redirect} = $formatted_subdomain . $request_ref->{current_link};
$log->info(
- "newtagid does not equal the original tagid, redirecting",
- {newtagid => $newtagid, redirect => $request_ref->{redirect}}
+ "new_tagid does not equal the original tagid, redirecting",
+ {new_tagid => $new_tagid, redirect => $request_ref->{redirect}}
) if $log->is_info();
redirect_to_url($request_ref, 302, $request_ref->{redirect});
}
my $description = '';
- my $products_title = $display_tag;
-
if ($tagtype eq 'users') {
my $user_ref = retrieve("$data_root/users/$tagid.sto");
if (defined $user_ref) {
if ((defined $user_ref->{name}) and ($user_ref->{name} ne '')) {
$title = $user_ref->{name} . " ($tagid)";
- $products_title = $user_ref->{name};
}
}
}
@@ -2996,196 +2975,86 @@ HEADER
return;
}
-# See issue 1960
-# a tag prefix, such as a minus sign, can indicate that a tag value should be excluded from a query
-# during processing this prefix may be removed from the current url link
-# this will add the prefix back
-# it will put the prefix before the string following the last forward slash in the link
-sub add_tag_prefix_to_link ($link, $tag_prefix) {
- $link =~ s/^(.*)\/(.*)$/$1\/$tag_prefix$2/;
- return $link;
-}
-
-=head2 display_tag ( $request_ref )
+=head2 canonicalize_request_tags_and_redirect_to_canonical_url ($request_ref)
-This function is called to display either:
-
-1. Products that have a specific tag: /category/cakes
- or that don't have a specific tag /category/-cakes
- or that have 2 specific tags /category/cake/brand/oreo
-2. List of tags of a given type: /labels
- possibly for products that have a specific tag: /category/cakes/labels
- or 2 specific tags: /category/cakes/label/organic/additives
-
-When displaying products for a tag, the function generates tag type specific HTML
-that is displayed at the top of the page:
-- tag parents and children
-- maps for tag types that have a location (e.g. packaging codes)
-- special properties for some tag types (e.g. additives)
-
-The function then calls search_and_display_products() to display the paginated list of products.
-
-When displaying a list of tags, the function calls display_list_of_tags().
+This function goes through the tags filters from the request and canonicalizes them.
+If the requested tags are not canonical, we will redirect to the canonical URL.
=cut
-sub display_tag ($request_ref) {
-
- my $title;
-
- my $tagtype = $request_ref->{tagtype};
- my $tagid = $request_ref->{tagid};
- my $display_tag;
- my $newtagid;
- my $newtagidpath;
- my $canon_tagid = undef;
-
- local $log->context->{tagtype} = $tagtype;
- local $log->context->{tagid} = $tagid;
+sub canonicalize_request_tags_and_redirect_to_canonical_url ($request_ref) {
- my $tagtype2 = $request_ref->{tagtype2};
- my $tagid2 = $request_ref->{tagid2};
- my $display_tag2;
- my $newtagid2;
- my $newtagid2path;
- my $canon_tagid2 = undef;
+ $request_ref->{current_link} = '';
+ $request_ref->{world_current_link} = '';
- local $log->context->{tagtype2} = $tagtype2;
- local $log->context->{tagid2} = $tagid2;
+ my $header_meta_noindex = 0; # Will be set if one of the tags is related to a user
+ my $redirect_to_canonical_url = 0; # Will be set if one of the tags is not canonical
- init_tags_texts() unless %tags_texts;
+ # Go through the tags filters from the request
- # Add a meta robot noindex for pages related to users
- if (
- (
- (defined $tagtype)
- and ($tagtype =~ /^(users|correctors|editors|informers|correctors|photographers|checkers)$/)
- )
- or ( (defined $tagtype2)
- and ($tagtype2 =~ /^(users|correctors|editors|informers|correctors|photographers|checkers)$/))
- )
- {
+ foreach my $tag_ref (@{$request_ref->{tags}}) {
- $header .= '' . "\n";
-
- }
+ # the tag name requested in url (in $lc language)
+ my $tagid = $tag_ref->{tagid};
+ my $tagtype = $tag_ref->{tagtype};
+ # in URLs, tags can be prefixed with a - (e.g /label/-organic)
+ # to indicate we want to match products without that tag
+ my $tag_prefix = $tag_ref->{tag_prefix};
+ # The tag name displayed in the page (in $lc language)
+ my $display_tag;
+ # canonical tag corresponding to tagid
+ my $canon_tagid;
+ # normalized tagid, in the $lc language
+ my $new_tagid;
+ my $new_tagid_path;
- if (defined $tagid) {
if (defined $taxonomy_fields{$tagtype}) {
$canon_tagid = canonicalize_taxonomy_tag($lc, $tagtype, $tagid);
$display_tag = display_taxonomy_tag($lc, $tagtype, $canon_tagid);
- $title = $display_tag;
- $newtagid = get_taxonomyid($lc, $display_tag);
- $log->info("displaying taxonomy tag", {canon_tagid => $canon_tagid, newtagid => $newtagid, title => $title})
+ $new_tagid = get_taxonomyid($lc, $display_tag);
+ $log->info("displaying taxonomy tag", {canon_tagid => $canon_tagid, new_tagid => $new_tagid})
if $log->is_info();
- if ($newtagid !~ /^(\w\w):/) {
- $newtagid = $lc . ':' . $newtagid;
+ if ($new_tagid !~ /^(\w\w):/) {
+ $new_tagid = $lc . ':' . $new_tagid;
}
- $newtagidpath = canonicalize_taxonomy_tag_link($lc, $tagtype, $newtagid);
- $request_ref->{current_link} = $newtagidpath;
- $request_ref->{world_current_link} = canonicalize_taxonomy_tag_link($lc, $tagtype, $canon_tagid);
+ $new_tagid_path = canonicalize_taxonomy_tag_link($lc, $tagtype, $new_tagid, $tag_prefix);
+ $request_ref->{current_link} .= $new_tagid_path;
+ $request_ref->{world_current_link}
+ .= canonicalize_taxonomy_tag_link($lc, $tagtype, $canon_tagid, $tag_prefix);
}
else {
$display_tag = canonicalize_tag2($tagtype, $tagid);
# Use "no_language" normalization for tags types without a taxonomy
- $newtagid = get_string_id_for_lang("no_language", $display_tag);
- $display_tag = display_tag_name($tagtype2, $display_tag);
+ $new_tagid = get_string_id_for_lang("no_language", $display_tag);
+ $display_tag = display_tag_name($tagtype, $display_tag);
if ($tagtype eq 'emb_codes') {
- $canon_tagid = $newtagid;
+ $canon_tagid = $new_tagid;
$canon_tagid =~ s/-($ec_code_regexp)$/-ec/ie;
}
- $title = $display_tag;
- $newtagidpath = canonicalize_tag_link($tagtype, $newtagid);
- $request_ref->{current_link} = $newtagidpath;
+ $new_tagid_path = canonicalize_tag_link($tagtype, $new_tagid, $tag_prefix);
+ $request_ref->{current_link} .= $new_tagid_path;
my $current_lang = $lang;
my $current_lc = $lc;
$lang = 'en';
$lc = 'en';
- $request_ref->{world_current_link} = canonicalize_tag_link($tagtype, $newtagid);
+ $request_ref->{world_current_link} .= canonicalize_tag_link($tagtype, $new_tagid, $tag_prefix);
$lang = $current_lang;
$lc = $current_lc;
- $log->info("displaying normal tag", {canon_tagid => $canon_tagid, newtagid => $newtagid, title => $title})
+ $log->info("displaying normal tag", {canon_tagid => $canon_tagid, new_tagid => $new_tagid})
if $log->is_info();
}
- # add back leading dash when a tag is excluded
- if ((defined $request_ref->{tag_prefix}) and ($request_ref->{tag_prefix} ne '')) {
- my $prefix = $request_ref->{tag_prefix};
- $request_ref->{current_link} = add_tag_prefix_to_link($request_ref->{current_link}, $prefix);
- $request_ref->{world_current_link} = add_tag_prefix_to_link($request_ref->{world_current_link}, $prefix);
- $log->debug("Found tag prefix ", {request => $request_ref}) if $log->is_debug();
- }
-
- $request_ref->{canon_tagid} = $canon_tagid;
- }
- else {
- $log->warn("no tagid found") if $log->is_warn();
- }
-
- # 2nd tag?
- if (defined $tagid2) {
- if (defined $taxonomy_fields{$tagtype2}) {
- $canon_tagid2 = canonicalize_taxonomy_tag($lc, $tagtype2, $tagid2);
- $display_tag2 = display_taxonomy_tag($lc, $tagtype2, $canon_tagid2);
- $title .= " / " . $display_tag2;
- $newtagid2 = get_taxonomyid($lc, $display_tag2);
- $log->info(
- "2nd level tag is a taxonomy tag",
- {
- tagtype2 => $tagtype2,
- tagid2 => $tagid2,
- canon_tagid2 => $canon_tagid2,
- newtagid2 => $newtagid2,
- title => $title
- }
- ) if $log->is_info();
- if ($newtagid2 !~ /^(\w\w):/) {
- $newtagid2 = $lc . ':' . $newtagid2;
- }
- $newtagid2path = canonicalize_taxonomy_tag_link($lc, $tagtype2, $newtagid2);
- $request_ref->{current_link} .= $newtagid2path;
- $request_ref->{world_current_link} .= canonicalize_taxonomy_tag_link($lc, $tagtype2, $canon_tagid2);
- }
- else {
- $display_tag2 = canonicalize_tag2($tagtype2, $tagid2);
- $newtagid2 = get_string_id_for_lang("no_language", $display_tag2);
- $display_tag2 = display_tag_name($tagtype2, $display_tag2);
- $title .= " / " . $display_tag2;
-
- if ($tagtype2 eq 'emb_codes') {
- $canon_tagid2 = $newtagid2;
- $canon_tagid2 =~ s/-($ec_code_regexp)$/-ec/ie;
- }
- $newtagid2path = canonicalize_tag_link($tagtype2, $newtagid2);
- $request_ref->{current_link} .= $newtagid2path;
- my $current_lang = $lang;
- my $current_lc = $lc;
- $lang = 'en';
- $lc = 'en';
- $request_ref->{world_current_link} .= canonicalize_tag_link($tagtype2, $newtagid2);
- $lang = $current_lang;
- $log->info(
- "2nd level tag is a normal tag",
- {
- tagtype2 => $tagtype2,
- tagid2 => $tagid2,
- canon_tagid2 => $canon_tagid2,
- newtagid2 => $newtagid2,
- title => $title
- }
- ) if $log->is_info();
- $lc = $current_lc;
- }
+ $tag_ref->{canon_tagid} = $canon_tagid;
+ $tag_ref->{new_tagid} = $new_tagid;
+ $tag_ref->{new_tagid_path} = $new_tagid_path;
+ $tag_ref->{display_tag} = $display_tag;
+ $tag_ref->{tagtype_path} = '/' . $tag_type_plural{$tagtype}{$lc};
+ $tag_ref->{tagtype_name} = lang_in_other_lc($lc, $tagtype . '_s');
- # add back leading dash when a tag is excluded
- if ((defined $request_ref->{tag2_prefix}) and ($request_ref->{tag2_prefix} ne '')) {
- my $prefix = $request_ref->{tag2_prefix};
- $request_ref->{current_link} = add_tag_prefix_to_link($request_ref->{current_link}, $prefix);
- $request_ref->{world_current_link} = add_tag_prefix_to_link($request_ref->{world_current_link}, $prefix);
- $log->debug("Found tag prefix 2 ", {request => $request_ref}) if $log->is_debug();
+ # We will redirect if the tag is not canonical
+ if ($new_tagid ne $tagid) {
+ $redirect_to_canonical_url = 1;
}
-
- $request_ref->{canon_tagid2} = $canon_tagid2;
}
if (defined $request_ref->{groupby_tagtype}) {
@@ -3195,7 +3064,7 @@ sub display_tag ($request_ref) {
# If the query contained tags in non-canonical form, redirect to the form with the canonical tags
# The redirect is temporary (302), as the canonicalization could change if the corresponding taxonomies change
- if (((defined $newtagid) and ($newtagid ne $tagid)) or ((defined $newtagid2) and ($newtagid2 ne $tagid2))) {
+ if ($redirect_to_canonical_url) {
$request_ref->{redirect} = $formatted_subdomain . $request_ref->{current_link};
# Re-add file suffix, so that the correct response format is kept. https://github.com/openfoodfacts/openfoodfacts-server/issues/894
$request_ref->{redirect} .= '.json' if single_param("json");
@@ -3207,152 +3076,128 @@ sub display_tag ($request_ref) {
redirect_to_url($request_ref, 302, $request_ref->{redirect});
}
- my $weblinks_html = '';
- my @wikidata_objects = ();
- if ( ($tagtype ne 'additives')
- and (not defined $request_ref->{groupby_tagtype}))
- {
- my @weblinks = ();
- if ((defined $properties{$tagtype}) and (defined $properties{$tagtype}{$canon_tagid})) {
- foreach my $key (keys %weblink_templates) {
- next if not defined $properties{$tagtype}{$canon_tagid}{$key};
- my $weblink = {
- text => $weblink_templates{$key}{text},
- href => sprintf($weblink_templates{$key}{href}, $properties{$tagtype}{$canon_tagid}{$key}),
- hreflang => $weblink_templates{$key}{hreflang},
- };
- $weblink->{title} = sprintf($weblink_templates{$key}{title}, $properties{$tagtype}{$canon_tagid}{$key})
- if defined $weblink_templates{$key}{title};
- push @weblinks, $weblink;
- }
+ # Ask search engines to not index the page if it is related to a user
+ if ($header_meta_noindex) {
+ $header .= '' . "\n";
+ }
- if ((defined $properties{$tagtype}) and (defined $properties{$tagtype}{$canon_tagid}{'wikidata:en'})) {
- push @wikidata_objects, $properties{$tagtype}{$canon_tagid}{'wikidata:en'};
- }
- }
+ return;
+}
- if (($#weblinks >= 0)) {
- $weblinks_html
- .= '
';
- }
- }
+Generate a title from the tags in the request.
- my $description = '';
+=head3 Parameters
- my $products_title = $display_tag;
+=head4 $tags_ref Array of tag filter objects
- my $icid = $tagid;
- (defined $icid) and $icid =~ s/^.*://;
+=head3 Return value
- # Gather data that will be passed to the tag template
- my $tag_template_data_ref = {};
+Title string.
- $tag_template_data_ref->{groupby_tagtype} = $request_ref->{groupby_tagtype};
+=cut
- if (defined $tagtype) {
+sub generate_title_from_request_tags ($tags_ref) {
- # check if there is a template to display additional fields from the taxonomy
- # the template is set in the Config.pm file
- # This feature was coded before the introduction of knowledge panels
- # It is in maintenance mode, and should be reimplemented as facets knowledge panels
- # (server side, or with client side facets knowledge panels)
+ my $title = join(" / ", map {($_->{tag_prefix} // '') . $_->{display_tag}} @{$tags_ref});
- if (exists $options{"display_tag_" . $tagtype}) {
+ return $title;
+}
- print STDERR "option display_tag_$tagtype\n";
+=head2 generate_description_from_display_tag_options ($tagtype, $tagid, $display_tag, $canon_tagid)
- foreach my $field_orig (@{$options{"display_tag_" . $tagtype}}) {
+Generate a description for some tag types, like additives, if there is a template set in the Config.pm file.
- my $field = $field_orig;
+This feature was coded before the introduction of knowledge panels.
+It is in maintenance mode, and should be reimplemented as facets knowledge panels
+(server side, or with client side facets knowledge panels)
- $log->debug("display_tag - field", {field => $field}) if $log->is_debug();
+=cut
- my $array = 0;
- if ($field =~ /^\@/) {
- $field = $';
- $array = 1;
- }
+sub generate_description_from_display_tag_options ($tagtype, $tagid, $display_tag, $canon_tagid) {
- # Section title?
+ my $description = "";
- if ($field =~ /^title:/) {
- $field = $';
- my $title = lang($tagtype . "_" . $field);
- ($title eq "") and $title = lang($field);
- $description .= "
([^<]+)<\/h3>\s*$//isg;
+
+ return $description;
+}
+
+=head2 display_tag ( $request_ref )
+
+This function is called to display either:
+
+1. Products that have a specific tag: /category/cakes
+ or that don't have a specific tag /category/-cakes
+ or that have 2 specific tags /category/cake/brand/oreo
+2. List of tags of a given type: /labels
+ possibly for products that have a specific tag: /category/cakes/labels
+ or more specific tags: /category/cakes/label/organic/additives
+
+When displaying products for a tag, the function generates tag type specific HTML
+that is displayed at the top of the page:
+- tag parents and children
+- maps for tag types that have a location (e.g. packaging codes)
+- special properties for some tag types (e.g. additives)
+
+The function then calls search_and_display_products() to display the paginated list of products.
+
+When displaying a list of tags, the function calls display_list_of_tags().
+
+=cut
+
+sub display_tag ($request_ref) {
+
+ local $log->context->{tags} = $request_ref->{tags};
+
+ init_tags_texts() unless %tags_texts;
+
+ canonicalize_request_tags_and_redirect_to_canonical_url($request_ref);
+
+ my $title = generate_title_from_request_tags($request_ref->{tags});
+
+ # Refactoring in progress
+ # TODO: some of the following variables may be removed, and instead we could use the $request_ref->{tags} array
+ my $tagtype = deep_get($request_ref, qw(tags 0 tagtype));
+ my $tagid = deep_get($request_ref, qw(tags 0 tagid));
+ my $display_tag = deep_get($request_ref, qw(tags 0 display_tag));
+ my $new_tagid = deep_get($request_ref, qw(tags 0 new_tagid));
+ my $new_tagid_path = deep_get($request_ref, qw(tags 0 new_tagid_path));
+ my $canon_tagid = deep_get($request_ref, qw(tags 0 canon_tagid));
+
+ my $tagtype2 = deep_get($request_ref, qw(tags 1 tagtype));
+ my $tagid2 = deep_get($request_ref, qw(tags 1 tagid));
+ my $display_tag2 = deep_get($request_ref, qw(tags 1 display_tag));
+ my $new_tagid2 = deep_get($request_ref, qw(tags 1 new_tagid));
+ my $new_tagid2path = deep_get($request_ref, qw(tags 1 new_tagid_path));
+ my $canon_tagid2 = deep_get($request_ref, qw(tags 1 canon_tagid));
+
+ my $weblinks_html = '';
+ my @wikidata_objects = ();
+ if ( ($tagtype ne 'additives')
+ and (not defined $request_ref->{groupby_tagtype}))
+ {
+ my @weblinks = ();
+ if ((defined $properties{$tagtype}) and (defined $properties{$tagtype}{$canon_tagid})) {
+ foreach my $key (keys %weblink_templates) {
+ next if not defined $properties{$tagtype}{$canon_tagid}{$key};
+ my $weblink = {
+ text => $weblink_templates{$key}{text},
+ href => sprintf($weblink_templates{$key}{href}, $properties{$tagtype}{$canon_tagid}{$key}),
+ hreflang => $weblink_templates{$key}{hreflang},
+ };
+ $weblink->{title} = sprintf($weblink_templates{$key}{title}, $properties{$tagtype}{$canon_tagid}{$key})
+ if defined $weblink_templates{$key}{title};
+ push @weblinks, $weblink;
}
- # Remove titles without content
+ if ((defined $properties{$tagtype}) and (defined $properties{$tagtype}{$canon_tagid}{'wikidata:en'})) {
+ push @wikidata_objects, $properties{$tagtype}{$canon_tagid}{'wikidata:en'};
+ }
+ }
- $description =~ s/