From 2e97532c88dacf9523576df4028b6f7df5967ea8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Mon, 19 Nov 2018 13:38:50 +0100 Subject: [PATCH] Fixt #349 (Normalisierung Artikel) - normalize_text_blocks nach Part-Controller migriert --- SL/Controller/Part.pm | 21 +++++++++++++++++++++ SL/IC.pm | 20 -------------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/SL/Controller/Part.pm b/SL/Controller/Part.pm index 804ad1590..357a3dd07 100644 --- a/SL/Controller/Part.pm +++ b/SL/Controller/Part.pm @@ -42,6 +42,8 @@ __PACKAGE__->run_before(sub { $::auth->assert('part_service_assembly_edit') }, __PACKAGE__->run_before('check_part_id', only => [ qw(edit delete) ]); +__PACKAGE__->run_before('normalize_text_blocks'); + # actions for editing parts # sub action_add_part { @@ -1193,6 +1195,25 @@ sub check_has_valid_part_type { die "invalid part_type" unless $_[0] =~ /^(part|service|assembly|assortment)$/; } + +sub normalize_text_blocks { + my ($self) = @_; + + # check if feature is enabled (select normalize_part_descriptions from defaults) + return unless ($::instance_conf->get_normalize_part_descriptions); + + # text block + foreach (qw(description)) { + $self->part->{$_} =~ s/\s+$//s; + $self->part->{$_} =~ s/^\s+//s; + $self->part->{$_} =~ s/ {2,}/ /g; + } + # html block (caveat: can be circumvented by using bold or italics) + $self->part->{notes} =~ s/^

( )+\s+/

/s; + $self->part->{notes} =~ s/( )+<\/p>$/<\/p>/s; + +} + sub render_assortment_items_to_html { my ($self, $assortment_items, $number_of_items) = @_; diff --git a/SL/IC.pm b/SL/IC.pm index 4254236db..f62c67695 100644 --- a/SL/IC.pm +++ b/SL/IC.pm @@ -954,24 +954,4 @@ sub prepare_parts_for_printing { return %template_arrays; } -sub normalize_text_blocks { - $main::lxdebug->enter_sub(); - - my $self = shift; - my %params = @_; - - my $form = $params{form} || $main::form; - - # check if feature is enabled (select normalize_part_descriptions from defaults) - return unless ($::instance_conf->get_normalize_part_descriptions); - - foreach (qw(description notes)) { - $form->{$_} =~ s/\s+$//s; - $form->{$_} =~ s/^\s+//s; - $form->{$_} =~ s/ {2,}/ /g; - } - $main::lxdebug->leave_sub(); -} - - 1; -- 2.20.1