Bug 35285: Add non-html template support to html_content wrapping

This patch adds support for messages generated using non-html formatted
notice templates to the html_content method of Koha::Notice::Message.

We continue to wrap content for html generated messages with the
appropriate headers, css and title.

For non-html generated content we wrap in the <div style="white-space:
pre-wrap"> block to maintain text formatting as defined in the original
plaintext template.

Test
Follow the test plan for bug 30287, nothing should outwardly change.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Martin Renvoize 2023-11-08 09:59:30 +00:00 committed by Katrin Fischer
parent 4d344fd3ab
commit 6b413acfc4
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834

View file

@ -31,6 +31,20 @@ Koha::Notice::Message - Koha notice message Object class, related to the message
=cut
=head3 is_html
my $bool = $message->is_html;
Returns a boolean denoting whether the message was generated using a preformatted html template.
=cut
sub is_html {
my ($self) = @_;
my $content_type = $self->content_type // '';
return $content_type =~ m/html/io;
}
=head3 html_content
my $wrapped_content = $message->html_content;
@ -45,10 +59,14 @@ sub html_content {
my $title = $self->subject;
my $content = $self->content;
my $css = C4::Context->preference("NoticeCSS") || '';
$css = qq{<link rel="stylesheet" type="text/css" href="$css">} if $css;
return <<EOS;
my $wrapped;
if ( $self->is_html ) {
my $css = C4::Context->preference("NoticeCSS") || '';
$css = qq{<link rel="stylesheet" type="text/css" href="$css">} if $css;
$wrapped = <<EOS;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
@ -62,7 +80,12 @@ sub html_content {
</body>
</html>
EOS
} else {
$wrapped = "<div style=\"white-space: pre-wrap;\">";
$wrapped .= $content;
$wrapped .= "</div>";
}
return $wrapped;
}
=head3 type