-
-
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 |
---|---|---|
|
@@ -69,7 +69,15 @@ 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()) { | ||
($this->set)($data, $form->getData()); | ||
$returnValue = ($this->set)($data, $form->getData()); | ||
$type = is_object($returnValue) ? get_class($returnValue) : gettype($returnValue); | ||
|
||
if ( | ||
(is_scalar($data) && gettype($data) === $type) | ||
|| (is_array($data) && is_array($returnValue)) | ||
|| (is_object($data) && $returnValue instanceof $type)) { | ||
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. [Immutability] We could also apply the same approach as data mappers but on the closure $builder->add('name', null, [
'set' => function(Category &$category, string $name) {
$category = $category->rename($name);
},
]); 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. Interesting idea. Passing the argument by reference also makes it clearer that you are always modifying the data directly, apart from being consistent with the data mapper API. |
||
$data = $returnValue; | ||
} | ||
} | ||
} | ||
} | ||
|
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.