-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[POC] [Form] Support get/set accessors for form fields #37614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,10 @@ | |
namespace Symfony\Component\Form\Extension\Core\DataMapper; | ||
|
||
use Symfony\Component\Form\DataMapperInterface; | ||
use Symfony\Component\Form\Exception\ExceptionInterface; | ||
use Symfony\Component\Form\Exception\UnexpectedTypeException; | ||
use Symfony\Component\Form\FormError; | ||
use TypeError; | ||
|
||
class AccessorMapper implements DataMapperInterface | ||
{ | ||
|
@@ -69,7 +72,13 @@ public function mapFormsToData(iterable $forms, &$data) | |
// Write-back is disabled if the form is not synchronized (transformation failed), | ||
// if the form was not submitted and if the form is disabled (modification not allowed) | ||
if (null !== $this->set && $config->getMapped() && $form->isSubmitted() && $form->isSynchronized() && !$form->isDisabled()) { | ||
$returnValue = ($this->set)($data, $form->getData()); | ||
try { | ||
$returnValue = ($this->set)($data, $form->getData()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given a compound form with two fields (let's say There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically, I expected something like this |
||
} catch (ExceptionInterface | TypeError $e) { | ||
$form->addError(new FormError($e->getMessage())); | ||
continue; | ||
} | ||
|
||
$type = is_object($returnValue) ? get_class($returnValue) : gettype($returnValue); | ||
|
||
if ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't be possible for
$this->set
to benull
as you checked it a few lines earlier (to fallback on the old datamapper).Unless I read something wrong ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct. I'll update this.