Skip to content

Commit

Permalink
Fix text field converter for PHP 8.1 getkirby#4226
Browse files Browse the repository at this point in the history
  • Loading branch information
afbora committed Mar 24, 2022
1 parent 8437921 commit 05d4d1e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 1 addition & 2 deletions config/fields/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@
return $value;
}

$value = trim($value);
$converter = $this->converters()[$this->converter()];

if (is_array($value) === true) {
return array_map($converter, $value);
}

return call_user_func($converter, $value);
return call_user_func($converter, trim($value ?? ''));
},
'converters' => function (): array {
return [
Expand Down
4 changes: 3 additions & 1 deletion tests/Form/Fields/TextFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public function converterDataProvider()
['slug', 'Super nice', 'super-nice'],
['upper', 'Super nice', 'SUPER NICE'],
['lower', 'Super nice', 'super nice'],
['ucfirst', 'super nice', 'Super nice']
['ucfirst', 'super nice', 'Super nice'],
['upper', null, ''],
['lower', '', ''],
];
}

Expand Down

0 comments on commit 05d4d1e

Please sign in to comment.