Access to CollectionType options in AdminType#6438
Access to CollectionType options in AdminType#6438VincentLanglet merged 1 commit intosonata-project:3.xfrom VincentLanglet:wip
Conversation
|
IMO When you exnteds I vote for |
|
Could you please rebase your PR and fix merge conflicts? |
|
Please review this bug fix @sonata-project/contributors |
|
Tests are failing now |
|
Fixed @jordisala1991 |
| // Note that the builder var is actually the formContractor: | ||
| $options = array_replace_recursive($this->builder->getDefaultOptions($type, $fieldDescription) ?? [], $options); | ||
| $options = array_replace_recursive( | ||
| $this->builder->getDefaultOptions($type, $fieldDescription, $options), |
There was a problem hiding this comment.
Probably I'm missing something, but why do we need to pass the form options to the builder (persistence bundles) if we already have them here?
Apparently https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1142/files this just adds the by_reference to the array.
There was a problem hiding this comment.
Because they are transformed.
From
$options = ['by_reference' => true];
To
$options = [`type_options` => ['by_reference' => true]]
(And multiple others modifications)
And the options passed are not always the same ; the depends on the type, etc
It the responsibility of the persistence bundle to re-format the options.
There was a problem hiding this comment.
I remember some unintended behavior regarding these options (#6078).
There was a problem hiding this comment.
Not sure to understand. ^^'
Is it an answer to franmomu ? A request change to me ?
There was a problem hiding this comment.
Sorry. The comment is regarding the modifications you've mentioned about the options.
There was a problem hiding this comment.
The reasoning seems fine to me.
I just have a concern. Since we are adding a 3rd argument in order to fix this issue properly in the next major, shouldn't be better to provide the fix by using this new argument through func_get_args() and deprecate the case where it's considered required and not used?
I didn't see how this new argument will be used in the method, so in case my previous concern can not be done, I think at least we should leave the comment with the code fragment that must be uncommented in the next major.
There was a problem hiding this comment.
I don't understand @phansys.
To me, the only NEXT_MAJOR comment needed is https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/3.x/src/Builder/FormContractor.php#L101
The 3rd argument will always be used from now, so I don't understand why you want to deprecate it ?
This is a long term fix.
There was a problem hiding this comment.
The 3rd argument will always be used from now, so I don't understand why you want to deprecate it ?
I'm not saying we should deprecate the argument, please re-read my comment:
deprecate the case where it's considered required and not used
There was a problem hiding this comment.
To me, the only NEXT_MAJOR comment needed is https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/3.x/src/Builder/FormContractor.php#L101
Sorry, didn't see that the call to func_get_args() and the NEXT_MAJOR comment were already there before this PR.
I think then we should just trigger a deprecation if the FormContractor::getDefaultOptions() method is called without the 3rd argument. Do you think it could be done in this PR?
There was a problem hiding this comment.
The getDefaultOptions is implemented in persistence bundle, so I can't do it in this SonataAdmin PR.
But I can create PR on persistence bundle then.
|
@franmomu Can we merge this bugfix and decide after if we need and how to refactor getDefaultOptions ? |
|
Please review @sonata-project/contributors |
This is related to #6426 (comment)
I need to know the CollectionType value of
by_referencein the AdminType.The options are passed to the AdminType here:
https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/3.x/src/Builder/FormContractor.php#L172-L180
So I need to change the signature of
getDefaultOptionsto allow passing theformOptions.But then I have two solutions:
symfony_form_optionsoption to the AdminType, then in the FormContractor I will addAnd then I access to
by_referencewith$options['symfony_form_options']['by_reference'] ?? true.by_referenceoption of the AdminType, then in the FormContractor I will addAnd then I access to
by_referencein the AdminType with$options['by_reference'].WDYT @sonata-project/contributors ?
In this PR I have implemented the code for the solution 1, but passing all the options seems overkill to me and I think the solution 2 more elegant.
Changelog