EasyAdminBundle
EasyAdminBundle copied to clipboard
ArrayField - formatValue
Hi,
formatValue() with ArrayField does not work.
The value remains the same. It is not formatted.
My code:
public function configureFields(string $pageName): iterable
{
yield ArrayField::new('sports')
->formatValue(fn ($items) => array_map(fn($item) => $this->translator->trans('sports'.'.'.$item), $items))
;
}
Having the same issue here. Instead of displaying the formatted value, it displays the original value.
ArrayField::new('spokenLanguages')
->formatValue(function ($languages) {
return \array_map(
function ($language) {
return LanguageEnum::toLabel($language);
},
$languages
);
})
->hideOnIndex()
,
same issue with me
Same problem, except formatValue() works on index page but not on detail page:
$expand = Action::DETAIL === $pageName;
yield ArrayField::new('sousSecteurs')
->formatValue(function (mixed $value) use ($expand) {
if ($value instanceof Collection && $value->count() > 0) {
$noms = $value->map(fn ($secteur) => $secteur->intitule)->toArray();
if ($expand) {
return implode(', ', $noms);
}
$display = array_slice($noms, 0, 2);
$suffix = count($noms) > 2 ? '...' : '';
return implode(', ', $display).$suffix;
} else {
return $value;
}
})
->hideOnForm()
;
Logic is executed as intended when $expand is false (on index page) but is ignored on detail page