Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Form] Mix attr option between guessed options and user options#22936
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
yceruto commentedMay 28, 2017
| Q | A |
|---|---|
| Branch? | 2.7 |
| Bug fix? | yes |
| New feature? | no |
| BC breaks? | no |
| Deprecations? | no |
| Tests pass? | yes |
| Fixed tickets | #19871 |
| License | MIT |
| // user options may override guessed options | ||
| if ($typeGuess) { | ||
| $options =array_merge($typeGuess->getOptions(),$options); | ||
| $options =array_replace_recursive($typeGuess->getOptions(),$options); |
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.
I am not sure if it is a good idea to apply this "globally". For theattr option, doing a recursive merge does work. But this may not be the case for all other options where the usage of some keys may be mutually exclusive.
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.
What we can do: First merge all guess options recursively and then do the merge here as before.
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.
But this may not be the case for all other options where the usage of some keys may be mutually exclusive.
Sorry :/ I don't see what I missing here, would you show me an example, please? I've done a simple test (https://3v4l.org/5FvnM) but I don't see what is wrong witharray_replace_recursive() function :/
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.
We don't know if it is allowed to use both keysbaz andbar at the same time for thefoo option.
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.
I suggest to change the code as follows:
$guessedOptions =array();if (null !==$pattern) {$guessedOptions =array_replace_recursive(array('attr' =>array('pattern' =>$pattern)),$guessedOptions);}if (null !==$maxLength) {$guessedOptions =array_replace_recursive(array('attr' =>array('maxlength' =>$maxLength)),$guessedOptions);}if ($requiredGuess) {$guessedOptions =array_merge(array('required' =>$requiredGuess->getValue()),$guessedOptions);}if ($typeGuess) {$guessedOptions =array_replace_recursive($typeGuess->getOptions(),$guessedOptions);}// user options may override guessed options$options =array_merge($guessedOptions,$options);
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.
Following the first assumption:
But this may not be the case for all other options where the usage of some keys may be mutually exclusive.
Still we can passfalse to the user option and it not will be displayed, i.e.:
$form->add('foo',null,array('foo' =>array('baz' =>false,'bar' =>'foobar')));//...$customGuessedOptions =array('foo' =>array('baz' =>'foobaz'));
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.
My comment above should have usedarray_replace_recursive() for the type guess too (I updated it).
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.
Losing themaxlength attribute when passing theattr option is expected IMO as you opted to be more clever than the guessers for theattr option.
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.
Losing the maxlength attribute when passing the attr option is expected IMO [...]
It's not a BC break? before this PR it's not true and the issue description proposes mixattr options also between guessed options and populated options, so now the one that is lost is me :)
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.
Losing the maxlength attribute when passing the attr option is expected
It should not as it could trigger an unwanted deprecation.
yceruto commentedMay 29, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I've updated the solution mixing Status: Needs Review |
fabpot commentedJun 3, 2017
Thank you@yceruto. |
…tions (yceruto)This PR was merged into the 2.7 branch.Discussion----------[Form] Mix attr option between guessed options and user options| Q | A| ------------- | ---| Branch? | 2.7| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#19871| License | MITCommits-------84f5de9 mix attr options between type-guess options and user options