-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[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
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9934c88
[Form] Deprecated option "read_only"
snoob 48ea257
Fixed spelling mistake
snoob 07c26cf
Removed an useless if
snoob 6fcb1ec
Changed the readonly test according to Tobion suggestion
snoob 00ad6ea
Revert the read_only view variable + test refactoring
snoob 45c5e3f
Fixed typo
snoob b5924e9
Applied webmozart advice
snoob c7abd9d
Applied webmozart feedback
snoob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget_attributes.html.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,21 +72,20 @@ public function buildView(FormView $view, FormInterface $form, array $options) | |
parent::buildView($view, $form, $options); | ||
|
||
$name = $form->getName(); | ||
$readOnly = $options['read_only']; | ||
|
||
if ($view->parent) { | ||
if ('' === $name) { | ||
throw new LogicException('Form node with empty name can be used only as root form node.'); | ||
} | ||
|
||
// 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'])) { | ||
$view->vars['attr']['readonly'] = true; | ||
} | ||
} | ||
|
||
$view->vars = array_replace($view->vars, array( | ||
'read_only' => $readOnly, | ||
'read_only' => $view->vars['attr']['readonly'], | ||
'errors' => $form->getErrors(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to keep the view variable to maintain bc. |
||
'valid' => $form->isSubmitted() ? $form->isValid() : true, | ||
'value' => $form->getViewData(), | ||
|
@@ -170,7 +169,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) | |
'data', | ||
)); | ||
|
||
// BC clause for the "max_length" and "pattern" option | ||
// BC clause for the "max_length", "pattern" and "read_only" option | ||
// Add these values to the "attr" option instead | ||
$defaultAttr = function (Options $options) { | ||
$attributes = array(); | ||
|
@@ -182,6 +181,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) | |
if (null !== $options['pattern']) { | ||
$attributes['pattern'] = $options['pattern']; | ||
} | ||
$attributes['readonly'] = $options['read_only']; | ||
|
||
return $attributes; | ||
}; | ||
|
@@ -191,7 +191,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) | |
'empty_data' => $emptyData, | ||
'trim' => true, | ||
'required' => true, | ||
'read_only' => false, | ||
'read_only' => false, // Deprecated use attr['readonly'] instead | ||
'max_length' => null, | ||
'pattern' => null, | ||
'property_path' => null, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1291,12 +1291,27 @@ public function testHidden() | |
); | ||
} | ||
|
||
public function testReadOnly() | ||
public function testReadOnlyBc() | ||
{ | ||
$form = $this->factory->createNamed('name', 'text', null, array( | ||
'read_only' => true, | ||
)); | ||
|
||
$this->assertWidgetMatchesXpath($form->createView(), array(), | ||
'/input | ||
[@type="text"] | ||
[@name="name"] | ||
[@readonly="readonly"] | ||
' | ||
); | ||
} | ||
|
||
public function testReadOnly() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please duplicate this test into a |
||
{ | ||
$form = $this->factory->createNamed('name', 'text', null, array( | ||
'attr' => array('readonly' => true), | ||
)); | ||
|
||
$this->assertWidgetMatchesXpath($form->createView(), array(), | ||
'/input | ||
[@type="text"] | ||
|
@@ -1899,8 +1914,7 @@ public function testWidgetAttributes() | |
$form = $this->factory->createNamed('text', 'text', 'value', array( | ||
'required' => true, | ||
'disabled' => true, | ||
'read_only' => true, | ||
'attr' => array('maxlength' => 10, 'pattern' => '\d+', 'class' => 'foobar', 'data-foo' => 'bar'), | ||
'attr' => array('maxlength' => 10, 'pattern' => '\d+', 'class' => 'foobar', 'data-foo' => 'bar', 'readonly' => true), | ||
)); | ||
|
||
$html = $this->renderWidget($form->createView()); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.