Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 777bf75c

Von Moritz Bunkus vor fast 17 Jahren hinzugefügt

  • ID 777bf75cfcfc81a87479a508ea900de4a64c483e
  • Vorgänger e5478aea
  • Nachfolger baba1fe9

Eine Hilfsfunktion, die aus Array- und Hashstrukturen in $form eine Liste von Variablennamen und Werten erzeugt, die dann wieder als versteckte Inputs in HTML-Formularen ausgegeben werden kann. Dabei sind die Variablennamen strukturiert (so wird z.B. aus "$form->{filter}->[0]->{description}" der Name "filter[+].description"). Außerdem eine Anpassung von $form->isblank(), die solch strukturierte Variablennamen versteht.

Unterschiede anzeigen:

SL/Form.pm
224 224
  return $self;
225 225
}
226 226

  
227
sub _flatten_variables_rec {
228
  $main::lxdebug->enter_sub(2);
229

  
230
  my $self   = shift;
231
  my $curr   = shift;
232
  my $prefix = shift;
233
  my $key    = shift;
234

  
235
  my @result;
236

  
237
  if ('' eq ref $curr->{$key}) {
238
    @result = ({ 'key' => $prefix . $key, 'value' => $curr->{$key} });
239

  
240
  } elsif ('HASH' eq ref $curr->{$key}) {
241
    foreach my $hash_key (sort keys %{ $curr->{$key} }) {
242
      push @result, $self->_flatten_variables_rec($curr->{$key}, $prefix . $key . '.', $hash_key);
243
    }
244

  
245
  } else {
246
    foreach my $idx (0 .. scalar @{ $curr->{$key} } - 1) {
247
      my $first_array_entry = 1;
248

  
249
      foreach my $hash_key (sort keys %{ $curr->{$key}->[$idx] }) {
250
        push @result, $self->_flatten_variables_rec($curr->{$key}->[$idx], $prefix . $key . ($first_array_entry ? '[+].' : '[].'), $hash_key);
251
        $first_array_entry = 0;
252
      }
253
    }
254
  }
255

  
256
  $main::lxdebug->leave_sub(2);
257

  
258
  return @result;
259
}
260

  
261
sub flatten_variables {
262
  $main::lxdebug->enter_sub(2);
263

  
264
  my $self = shift;
265
  my @keys = @_;
266

  
267
  my @variables;
268

  
269
  foreach (@keys) {
270
    push @variables, $self->_flatten_variables_rec($self, '', $_);
271
  }
272

  
273
  $main::lxdebug->leave_sub(2);
274

  
275
  return @variables;
276
}
277

  
278

  
227 279
sub debug {
228 280
  $main::lxdebug->enter_sub();
229 281

  
......
395 447

  
396 448
  my ($self, $name, $msg) = @_;
397 449

  
398
  if ($self->{$name} =~ /^\s*$/) {
399
    $self->error($msg);
450
  my $curr = $self;
451
  foreach my $part (split '.', $name) {
452
    if (!$curr->{$part} || ($curr->{$part} =~ /^\s*$/)) {
453
      $self->error($msg);
454
    }
455
    $curr = $curr->{$part};
400 456
  }
457

  
401 458
  $main::lxdebug->leave_sub();
402 459
}
403 460

  

Auch abrufbar als: Unified diff