Sometimes you have a small little class like Rate.php and want to use it with a symfony form like:
$builder
->add('cost', MoneyType::class, [
'currency' => 'EUR',
'label' => 'Cost',
'divisor' => 100,
]);
But S*** symfony forms expects a set<name>
method. Let's change this behaviour by using a custom property accessor and overriding the path.
$builder
->setDataMapper(new PropertyPathMapper(
new CustomPropertyAccessor([ 'cost' => 'changeCost' ])
));
All done.
This gist comes up often for me in google search. So for all of you who come here searching how to change property path, you don't need to use this way. You can do this via...
property_path
option.