Created
June 22, 2015 18:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MoneyType extends AbstractType implements DataMapperInterface | |
{ | |
public function buildForm(FormBuilder $builder, array $options) | |
{ | |
$builder | |
->add('amount', 'integer') | |
->add('currency', 'string') | |
->setDataMapper($this) | |
; | |
} | |
public function mapDataToForms($data, $forms) | |
{ | |
foreach ($forms as $form) { | |
switch ($form->getName()) { | |
case 'amount': | |
$form->setData($data->getAmount()); | |
break; | |
case 'currency': | |
$form->setData($data->getCurrency()); | |
break; | |
} | |
} | |
} | |
public function mapFormsToData($forms, &$data) | |
{ | |
$forms = iterator_to_array($forms); | |
$data = new Money($forms['amount']->getData(), $forms['currency']->getData()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
would be nice to gets its usage too like:
and also say that should the type have less fields than the VO you can also copy those over to the VO from the $data coming into the call to
mapFormsToData($forms, &$data)
😸