Skip to content

Commit b8f76a8

Browse files
committed
Add preProcessIndex method to field type
1 parent effde84 commit b8f76a8

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/Fieldtypes/CurrencyFieldtype.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public function defaultValue()
3131
* Pre-process the data before it gets sent to the publish page.
3232
*
3333
* @param mixed $data
34-
* @return array|mixed
34+
* @return string|null
3535
*/
36-
public function preProcess($data)
36+
public function preProcess($data): ?string
3737
{
3838
if ($data === null) {
3939
return null;
@@ -46,6 +46,22 @@ public function preProcess($data)
4646
return trim(str_replace($symbol, '', $formatted));
4747
}
4848

49+
/**
50+
* Pre-process the data before it gets sent to the publish page.
51+
*
52+
* @param $data
53+
* @return string|null
54+
*/
55+
public function preProcessIndex($data): ?string
56+
{
57+
if ($data === null) {
58+
return null;
59+
}
60+
61+
$fmt = App::make(NumberFormatter::class, ['iso' => $this->getIso()]);
62+
return $fmt->formatCurrency($data, $this->getIso());
63+
}
64+
4965
/**
5066
* Process the data before it gets saved.
5167
*

0 commit comments

Comments
 (0)