-
Notifications
You must be signed in to change notification settings - Fork 92
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
feat: stub DataMapperInterface #418
base: 2.0.x
Are you sure you want to change the base?
Conversation
Ensure TData of FormInterface is provided Set TData on mixed since we don't know the type of the child forms Add template for in DataMapperInterface refs: phpstan#417
* @param TViewData $viewData | ||
* @param \Traversable<mixed, FormInterface<mixed>> $forms | ||
*/ | ||
public function mapDataToForms(mixed $viewData, \Traversable $forms): void; | ||
|
||
/** | ||
* @param \Traversable<mixed, FormInterface<mixed>> $forms | ||
* @param TViewData $viewData | ||
* @param-out TViewData $viewData | ||
*/ | ||
public function mapFormsToData(\Traversable $forms, mixed &$viewData): void; |
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.
As it's stated in the docs ( https://symfony.com/doc/current/form/data_mappers.html#creating-a-data-mapper ), the following logic is needed:
// there is no data yet, so nothing to prepopulate
if (null === $viewData) {
return;
}
This, as it seems that mapDataToForms
is called before the data is avaialble. Which will mean that $viewData
will be null
at that time.
Thus I propose the following change:
* @param TViewData $viewData | |
* @param \Traversable<mixed, FormInterface<mixed>> $forms | |
*/ | |
public function mapDataToForms(mixed $viewData, \Traversable $forms): void; | |
/** | |
* @param \Traversable<mixed, FormInterface<mixed>> $forms | |
* @param TViewData $viewData | |
* @param-out TViewData $viewData | |
*/ | |
public function mapFormsToData(\Traversable $forms, mixed &$viewData): void; | |
* @param TViewData|null $viewData | |
* @param \Traversable<mixed, FormInterface<mixed>> $forms | |
*/ | |
public function mapDataToForms(mixed $viewData, \Traversable $forms): void; | |
/** | |
* @param \Traversable<mixed, FormInterface<mixed>> $forms | |
* @param TViewData|null $viewData | |
* @param-out TViewData $viewData | |
*/ | |
public function mapFormsToData(\Traversable $forms, mixed &$viewData): void; |
For example, the stub file for the FormTypeInterface
also has a generic type, but also has it defined nullable when it's being passed to it's buildForm
method.
I've set TData of FormInterface to mixed since each child form can have a different type.
refs: #417