Skip to content

Commit c96081f

Browse files
authored
fix exception in formatter utils (#107)
1 parent d55c354 commit c96081f

4 files changed

Lines changed: 21 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [3.10.1] - 2026-02-10
6+
- Fixed: exception in FormatterUtil when value is null
7+
58
## [3.10.0] - 2026-01-22
69
- Added: Option to adjust the field where the alias is generated from (instead of overriding the complete method) ([#106](https://github.com/heimrichhannot/contao-utils-bundle/pull/106))
710
- Added: AliasFieldConfiguration::setGenerateAliasCallback() ([#106](https://github.com/heimrichhannot/contao-utils-bundle/pull/106))

src/EntityFinder/Element.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function __construct(
1212
public readonly int $id,
1313
public readonly string $table,
1414
public readonly ?string $description = null,
15-
public readonly ?iterable $parents = null
15+
public readonly iterable|null $parents = null
1616
)
1717
{
1818
}

src/Util/FormatterUtil.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,12 @@ public function formatDcaFieldValue(
168168
: $reference;
169169
}
170170

171-
if ($settings->replaceInsertTags)
172-
{
173-
$value = $this->insertTagParser->replace($value);
171+
if (is_int($value) || null === $value) {
172+
return $value;
173+
}
174+
175+
if ($settings->replaceInsertTags) {
176+
$value = $this->insertTagParser->replace((string)$value);
174177
}
175178

176179
return Str::specialchars($value);

tests/Util/FormatterUtilTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,16 @@ public function testFormatDcaFieldValue()
7070
->setDcaOverride(['inputType' => 'text'])
7171
)
7272
);
73+
74+
$this->assertEquals(
75+
'',
76+
$formatterUtil->formatDcaFieldValue(
77+
$dataContainer,
78+
'message',
79+
null,
80+
FormatterUtil\FormatDcaFieldValueOptions::create()
81+
->setDcaOverride(['inputType' => 'textarea'])
82+
)
83+
);
7384
}
7485
}

0 commit comments

Comments
 (0)