From fb7bf8f95e14e8ae02c1a200297077b22a353c54 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 10 Mar 2023 10:47:51 +0000 Subject: [PATCH] Bug 29046: Use EmailFieldPrecedence in first_valid_email_address This patch update the Koha::Patron->first_valid_email_address method to use the newly defined EmailFieldPrecedence preference. Signed-off-by: Caroline Cyr La Rose Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- Koha/Patron.pm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 5b312a3df7..2a8eecf9f6 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1436,7 +1436,16 @@ Returns the empty string if the borrower has no email addresses. sub first_valid_email_address { my ($self) = @_; - return $self->email() || $self->emailpro() || $self->B_email() || q{}; + my $email = q{}; + + my @fields = split /\s*\|\s*/, + C4::Context->preference('EmailFieldPrecedence'); + for my $field (@fields) { + $email = $self->$field; + last if ( $email ne q{} ); + } + + return $email; } =head3 get_club_enrollments -- 2.39.5