From cd9133bbe3a22c148a00d17e52f9b453282fa3d9 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Thu, 3 Nov 2022 11:02:21 +0000
Subject: [PATCH] Bug 26635: (follow-up) Add optional support for `:` as the
 modifier

This patch adds optional support for using `:` as the modifier for
invoking the 'count' method for relations as discussed.

We retain support for `+` for backward compatability to prevent a
breaking change.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
---
 Koha/REST/Plugin/Query.pm  | 2 +-
 t/Koha/REST/Plugin/Query.t | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/Koha/REST/Plugin/Query.pm b/Koha/REST/Plugin/Query.pm
index f75d284625..04666168f8 100644
--- a/Koha/REST/Plugin/Query.pm
+++ b/Koha/REST/Plugin/Query.pm
@@ -364,7 +364,7 @@ sub _parse_embed {
         $result->{$curr} = { children => _parse_embed( $next ) };
     }
     else {
-        if ( $curr =~ m/^(?<relation>.*)\+count/ ) {
+        if ( $curr =~ m/^(?<relation>.*)[\+|:]count/ ) {
             my $key = $+{relation} . "_count";
             $result->{$key} = { is_count => 1 };
         }
diff --git a/t/Koha/REST/Plugin/Query.t b/t/Koha/REST/Plugin/Query.t
index 509f4f9ff6..b4edbdaf1d 100755
--- a/t/Koha/REST/Plugin/Query.t
+++ b/t/Koha/REST/Plugin/Query.t
@@ -433,7 +433,7 @@ subtest '_build_query_params_from_api' => sub {
 
 subtest 'stash_embed() tests' => sub {
 
-    plan tests => 14;
+    plan tests => 16;
 
     my $t = Test::Mojo->new;
 
@@ -446,6 +446,9 @@ subtest 'stash_embed() tests' => sub {
     $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'holds+count' } )
       ->json_is( '/embed' => { holds_count => { is_count => 1 } } );
 
+    $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'holds:count' } )
+      ->json_is( '/embed' => { holds_count => { is_count => 1 } } );
+
     $t->get_ok( '/stash_embed' => { 'x-koha-embed' => 'checkouts,checkouts.item,patron' } )
       ->json_is( '/embed' => {
             checkouts => { children => { item => {} } },
-- 
2.30.2