Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Closed
wants to merge 8 commits into from
Closed

[Form] Fix #10658 Deprecate "read_only" option #10676

wants to merge 8 commits into from

Conversation

snoob
Copy link
Contributor

@snoob 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

@romainneutron
Copy link
Contributor

You have to add a note about the deprecation in the changelog

@snoob
Copy link
Contributor Author

snoob commented Apr 9, 2014

@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));
Copy link
Contributor

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']...

Copy link
Contributor Author

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.

Copy link
Contributor

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']

@stof stof added the Form label Apr 10, 2014
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'readonly'

@rpg600
Copy link
Contributor

rpg600 commented Jul 11, 2014

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']) {
Copy link
Contributor

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?

@snoob
Copy link
Contributor Author

snoob commented Jul 16, 2014

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)))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@snoob
Copy link
Contributor Author

snoob commented Jul 19, 2014

@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']);
Copy link
Contributor

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 ?>
Copy link
Contributor

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?

Copy link
Contributor Author

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?

@Tobion
Copy link
Contributor

Tobion commented Oct 7, 2014

As this is almost done, can we finish it?
Just needs one line change, rebase and changelog entry.

@snoob
Copy link
Contributor Author

snoob commented Oct 14, 2014

@Tobion : Which line have i missed?

@Tobion
Copy link
Contributor

Tobion commented Oct 14, 2014

@snoob
Copy link
Contributor Author

snoob commented Oct 14, 2014

@Tobion
Copy link
Contributor

Tobion commented Oct 14, 2014

You don't understand: It should be $view->vars['attr']['readonly'] = true;

@wouterj
Copy link
Member

wouterj commented Nov 2, 2014

ping @snoob

@snoob
Copy link
Contributor Author

snoob commented Nov 3, 2014

@Tobion Sorry i had no time i ll try to fix today but i want to be sure about the rendering wanted.
Before :
<input type="text" readonly="readonly">
After
<input type="text" readonly> (like disabled)
Is that ok for you? May i change the Symfony version too i wrote deprecated since 2.6 but i think it will be 2.7 now as the PR took time?

@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)

@Tobion
Copy link
Contributor

Tobion commented Nov 3, 2014

The rendering should stay the same with <input type="text" readonly="readonly"> even when readonly = true as this is how the template renders boolean values.

@snoob
Copy link
Contributor Author

snoob commented Nov 3, 2014

Ok thank you

@Tobion
Copy link
Contributor

Tobion commented Nov 3, 2014

And disabled is also disabled="disabled". Why do you say it's not?

@snoob
Copy link
Contributor Author

snoob commented Nov 3, 2014

I thought it was i missed the boolean part conversion my bad

@Tobion
Copy link
Contributor

Tobion commented Nov 3, 2014

Hm I think this PR still breaks for people who used 'read_only' => true option and at the same time passed some custom attributes. This will currently result in a field that is not read only.

@snoob
Copy link
Contributor Author

snoob commented Nov 6, 2014

@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'])) {
Copy link
Contributor

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.

@Tobion
Copy link
Contributor

Tobion commented Apr 18, 2015

Another problem apart from #10676 (comment) is that people who used a custom theme will probably have readonly be rendered twice since it is now also added to the attr.

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.

@Tobion
Copy link
Contributor

Tobion commented Apr 19, 2015

Closed in favor of #14403

@Tobion Tobion closed this Apr 19, 2015
fabpot added a commit that referenced this pull request May 20, 2015
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants