-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Fix #10658 Deprecate "read_only" option #10676
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
Conversation
snoob
commented
Apr 9, 2014
Q | A |
---|---|
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | yes |
Tests pass? | yes |
Fixed tickets | #10658 |
License | MIT |
Doc PR | symfony/symfony-docs#3782 |
You have to add a note about the deprecation in the changelog |
@webmozart : Do you want to keep the template variable? |
@@ -72,7 +72,8 @@ public function buildView(FormView $view, FormInterface $form, array $options) | |||
parent::buildView($view, $form, $options); | |||
|
|||
$name = $form->getName(); | |||
$readOnly = $options['read_only']; | |||
|
|||
$readOnly = isset($view->vars['attr']['readonly']) && in_array($view->vars['attr']['readonly'], array('readonly', true)); |
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.
Shouldn't you just call the isset()
? Cause here you do the strange in_array()
, but later when fixing BC you just call: false !== $options['read_only']
...
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.
If we just call the isset()
method we will be able to pass any value in the readonly attr (except for false) that's why i secured the test with an in_array()
method.
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 need to reverse the logic. According to html spec a boolean property is active when it is set (whatever the value). So readonly="0"
is also readonly.
So I'd suggest $readOnly = isset($view->vars['attr']['readonly']) && false !== $view->vars['attr']['readonly']
@@ -191,7 +196,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) | |||
'empty_data' => $emptyData, | |||
'trim' => true, | |||
'required' => true, | |||
'read_only' => false, | |||
'read_only' => false, //Deprecated use attr['read_only'] instead |
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.
'readonly'
You can close this PR and merge #11376 instead. |
@@ -183,6 +184,10 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) | |||
$attributes['pattern'] = $options['pattern']; | |||
} | |||
|
|||
if (false !== $options['read_only']) { |
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 don't see why this is necessary?
I have done the missing changes on this PR it's not necessary to merge the #11376. |
@@ -80,13 +81,12 @@ public function buildView(FormView $view, FormInterface $form, array $options) | |||
} | |||
|
|||
// Complex fields are read-only if they themselves or their parents are. | |||
if (!$readOnly) { | |||
$readOnly = $view->parent->vars['read_only']; | |||
if (!$readOnly && (isset($view->parent->vars['attr']['readonly']) && in_array($view->parent->vars['attr']['readonly'], array('readonly', true)))) { |
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.
same as above
@Tobion : I agree with you (about html spec). I've done the changes |
@@ -127,7 +127,7 @@ public function testNonReadOnlyFormWithNonReadOnlyParentIsNotReadOnly() | |||
->getForm() | |||
->createView(); | |||
|
|||
$this->assertFalse($view['child']->vars['read_only']); | |||
$this->assertEquals(false, $view['child']->vars['attr']['readonly']); |
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.
assertFalse
@@ -1,5 +1,4 @@ | |||
id="<?php echo $view->escape($id) ?>" name="<?php echo $view->escape($full_name) ?>" <?php if ($read_only): ?>readonly="readonly" <?php endif ?> | |||
<?php if ($disabled): ?>disabled="disabled" <?php endif ?> | |||
id="<?php echo $view->escape($id) ?>" name="<?php echo $view->escape($full_name) ?>" <?php if ($disabled): ?>disabled="disabled" <?php endif ?> |
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.
Could you move the disabled clause to the next line, as it were?
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.
Maybe the spaces should be before the html attributes in the php file too as it has been done on the twig form layout?
As this is almost done, can we finish it? |
@Tobion : Which line have i missed? |
I have already added this line https://github.com/snoob/symfony/commit/b5924e98aa04dca2f8e3acef031afee3565e9e12#diff-1 |
You don't understand: It should be |
ping @snoob |
@Tobion Sorry i had no time i ll try to fix today but i want to be sure about the rendering wanted. @webmozart : I have notice that the spaces in the form_widget.php are before attributes whereas they are after in twig (the second one makes for sense) |
The rendering should stay the same with |
Ok thank you |
And disabled is also |
I thought it was i missed the boolean part conversion my bad |
Hm I think this PR still breaks for people who used |
@webmozart : Can i rebase now? May i change the version too ? (deprecated since symfony 2.7 ?) |
@@ -80,13 +79,13 @@ public function buildView(FormView $view, FormInterface $form, array $options) | |||
} | |||
|
|||
// Complex fields are read-only if they themselves or their parents are. | |||
if (!$readOnly) { | |||
$readOnly = $view->parent->vars['read_only']; | |||
if (!$view->vars['attr']['readonly'] && (isset($view->parent->vars['attr']['readonly']) && false !== $view->parent->vars['attr']['readonly'])) { |
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 don't think view->vars['attr']['readonly']
is ensured to be set.
Another problem apart from #10676 (comment) is that people who used a custom theme will probably have So I think the only thing we can do is to just deprecate the option by triggering an deprecation via a option normalizer as done for other options. |
Closed in favor of #14403 |
This PR was squashed before being merged into the 2.8 branch (closes #14403). Discussion ---------- [Form] deprecate read_only option | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #10658 | License | MIT | Doc PR | symfony/symfony-docs#3782 Replaces #10676 with a slightly different implementation. - fixes BC break when 'read_only' => true option and at the same time custom attributes are used by using a normalizer - adds deprecation notice - keeps legacy tests Commits ------- 53330e1 [Form] deprecate read_only option