Fixt #349 (Normalisierung Artikel) - normalize_text_blocks nach Part-Controller migriert
authorJan Büren <jan@kivitendo.de>
Mon, 19 Nov 2018 12:38:50 +0000 (13:38 +0100)
committerJan Büren <jan@kivitendo.de>
Mon, 19 Nov 2018 12:40:16 +0000 (13:40 +0100)
SL/Controller/Part.pm
SL/IC.pm

index 804ad15..357a3dd 100644 (file)
@@ -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/^<p>(&nbsp;)+\s+/<p>/s;
+  $self->part->{notes} =~ s/(&nbsp;)+<\/p>$/<\/p>/s;
+
+}
+
 sub render_assortment_items_to_html {
   my ($self, $assortment_items, $number_of_items) = @_;
 
index 4254236..f62c676 100644 (file)
--- 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;