8000 [Form] Revert "merged branch helmer/readonly (PR #3193)" · vicb/symfony@ccd8b67 · GitHub
[go: up one dir, main page]

Skip to content

Commit ccd8b67

Browse files
committed
[Form] Revert "merged branch helmer/readonly (PR symfony#3193)"
This reverts commit e71d157, reversing changes made to 253a8ff. Conflicts: src/Symfony/Component/Form/Form.php src/Symfony/Component/Form/Tests/FormFactoryTest.php
1 parent 43604e2 commit ccd8b67

File tree

10 files changed

+64
-85
lines changed

10 files changed

+64
-85
lines changed

src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295

296296
{% block widget_attributes %}
297297
{% spaceless %}
298-
id="{{ id }}" name="{{ full_name }}"{% if read_only %} readonly="readonly"{% endif %}{% if disabled %} disabled="disabled"{% endif %}{% if required %} required="required"{% endif %}{% if max_length %} maxlength="{{ max_length }}"{% endif %}{% if pattern %} pattern="{{ pattern }}"{% endif %}
298+
id="{{ id }}" name="{{ full_name }}"{% if read_only %} disabled="disabled"{% endif %}{% if required %} required="required"{% endif %}{% if max_length %} maxlength="{{ max_length }}"{% endif %}{% if pattern %} pattern="{{ pattern }}"{% endif %}
299299
{% for attrname,attrvalue in attr %}{{attrname}}="{{attrvalue}}" {% endfor %}
300300
{% endspaceless %}
301301
{% endblock widget_attributes %}

src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/attributes.html.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
id="<?php echo $view->escape($id) ?>"
22
name="<?php echo $view->escape($full_name) ?>"
3-
<?php if ($read_only): ?>readonly="readonly" <?php endif ?>
4-
<?php if ($disabled): ?>disabled="disabled" <?php endif ?>
3+
<?php if ($read_only): ?>disabled="disabled" <?php endif ?>
54
<?php if ($required): ?>required="required" <?php endif ?>
65
<?php if ($max_length): ?>maxlength="<?php echo $view->escape($max_length) ?>" <?php endif ?>
76
<?php if ($pattern): ?>pattern="<?php echo $view->escape($pattern) ?>" <?php endif ?>

src/Symfony/Component/Form/Extension/Core/Type/FieldType.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ public function buildForm(FormBuilder $builder, array $options)
4545

4646
$builder
4747
->setRequired($options['required'])
48-
->setDisabled($options['disabled'])
48+
->setReadOnly($options['read_only'])
4949
->setErrorBubbling($options['error_bubbling'])
5050
->setEmptyData($options['empty_data'])
51-
->setAttribute('read_only', $options['read_only'])
5251
->setAttribute('by_reference', $options['by_reference'])
5352
->setAttribute('property_path', $options['property_path'])
5453
->setAttribute('error_mapping', $options['error_mapping'])
@@ -109,8 +108,7 @@ public function buildView(FormView $view, FormInterface $form)
109108
->set('full_name', $fullName)
110109
->set('errors', $form->getErrors())
111110
->set('value', $form->getClientData())
112-
->set('read_only', $form->getAttribute('read_only'))
113-
->set('disabled', $form->isDisabled())
111+
->set('read_only', $form->isReadOnly())
114112
->set('required', $form->isRequired())
115113
->set('max_length', $form->getAttribute('max_length'))
116114
->set('pattern', $form->getAttribute('pattern'))
@@ -161,7 +159,6 @@ public function getDefaultOptions()
161159
'trim' => true,
162160
'required' => true,
163161
'read_only' => false,
164-
'disabled' => false,
165162
'max_length' => null,
166163
'pattern' => null,
167164
'property_path' => null,

src/Symfony/Component/Form/Form.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class Form implements \IteratorAggregate, FormInterface
167167
* Whether this form may only be read, but not bound
168168
* @var Boolean
169169
*/
170-
private $disabled = false;
170+
private $readOnly = false;
171171

172172
/**
173173
* The dispatcher for distributing events of this form
@@ -191,7 +191,7 @@ public function __construct($name, EventDispatcherInterface $dispatcher,
191191
array $types = array(), array $clientTransformers = array(),
192192
array $normTransformers = array(),
193193
DataMapperInterface $dataMapper = null, array $validators = array(),
194-
$required = false, $disabled = false, $errorBubbling = false,
194+
$required = false, $readOnly = false, $errorBubbling = false,
195195
$emptyData = null, array $attributes = array())
196196
{
197197
$name = (string) $name;
@@ -224,7 +224,7 @@ public function __construct($name, EventDispatcherInterface $dispatcher,
224224
$this->dataMapper = $dataMapper;
225225
$this->validators = $validators;
226226
$this->required = (Boolean) $required;
227-
$this->disabled = (Boolean) $disabled;
227+
$this->readOnly = (Boolean) $readOnly;
228228
$this->errorBubbling = (Boolean) $errorBubbling;
229229
$this->emptyData = $emptyData;
230230
$this->attributes = $attributes;
@@ -271,19 +271,29 @@ public function getTypes()
271271
public function isRequired()
272272
{
273273
if (null === $this->parent || $this->parent->isRequired()) {
274+
274275
return $this->required;
275276
}
276277

277278
return false;
278279
}
279280

280281
/**
281-
* {@inheritDoc}
282+
* Returns whether this form is read only.
283+
*
284+
* The content of a read-only form is displayed, but not allowed to be
285+
* modified. The validation of modified read-only forms should fail.
286+
*
287+
* Fields whose parents are read-only are considered read-only regardless of
288+
* their own state.
289+
*
290+
* @return Boolean
282291
*/
283-
public function isDisabled()
292+
public function isReadOnly()
284293
{
285-
if (null === $this->parent || !$this->parent->isDisabled()) {
286-
return $this->disabled;
294+
if (null === $this->parent || !$this->parent->isReadOnly()) {
295+
296+
return $this->readOnly;
287297
}
288298

289299
return true;
@@ -464,7 +474,7 @@ public function bind($clientData)
464474
throw new AlreadyBoundException('A form can only be bound once');
465475
}
466476

467-
if ($this->isDisabled()) {
477+
if ($this->readOnly) {
468478
$this->bound = true;
469479

470480
return $this;
@@ -694,6 +704,7 @@ public function isEmpty()
694704
{
695705
foreach ($this->children as $child) {
696706
if (!$child->isEmpty()) {
707+
697708
return false;
698709
}
699710
}
@@ -716,9 +727,10 @@ public function isValid()
716727
return false;
717728
}
718729

719-
if (!$this->isDisabled()) {
730+
if (!$this->readOnly) {
720731
foreach ($this->children as $child) {
721732
if (!$child->isValid()) {
733+
722734
return false;
723735
}
724736
}
@@ -891,6 +903,7 @@ public function has($name)
891903
public function get($name)
892904
{
893905
if (isset($this->children[$name])) {
906+
894907
return $this->children[$name];
895908
}
896909

src/Symfony/Component/Form/FormBuilder.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class FormBuilder
4949
/**
5050
* @var Boolean
5151
*/
52-
private $disabled;
52+
private $readOnly;
5353

5454
/**
5555
* @var Boolean
@@ -187,27 +187,27 @@ public function getData()
187187
}
188188

189189
/**
190-
* Set whether the form is disabled
190+
* Set whether the form is read only
191191
*
192-
* @param Boolean $disabled Whether the form is disabled
192+
* @param Boolean $readOnly Whether the form is read only
193193
*
194194
* @return FormBuilder The current builder
195195
*/
196-
public function setDisabled($disabled)
196+
public function setReadOnly($readOnly)
197197
{
198-
$this->disabled = (Boolean) $disabled;
198+
$this->readOnly = (Boolean) $readOnly;
199199

200200
return $this;
201201
}
202202

203203
/**
204-
* Returns whether the form is disabled.
204+
* Returns whether the form is read only.
205205
*
206-
* @return Boolean Whether the form is disabled
206+
* @return Boolean Whether the form is read only
207207
*/
208-
public function getDisabled()
208+
public function getReadOnly()
209209
{
210-
return $this->disabled;
210+
return $this->readOnly;
211211
}
212212

213213
/**
@@ -676,7 +676,7 @@ public function getForm()
676676
$this->getDataMapper(),
677677
$this->getValidators(),
678678
$this->getRequired(),
679-
$this->getDisabled(),
679+
$this->getReadOnly(),
680680
$this->getErrorBubbling(),
681681
$this->getEmptyData(),
682682
$this->getAttributes()

src/Symfony/Component/Form/FormInterface.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,17 @@ function isValid();
178178
function isRequired();
179179

180180
/**
181-
* Returns whether this form is disabled.
181+
* Returns whether this form can be read only.
1 10000 82182
*
183-
* The content of a disabled form is displayed, but not allowed to be
184-
* modified. The validation of modified disabled forms should fail.
183+
* The content of a read-only form is displayed, but not allowed to be
184+
* modified. The validation of modified read-only forms should fail.
185185
*
186-
* Fields whose parents are disabled are considered disabled regardless of
186+
* Fields whose parents are read-only are considered read-only regardless of
187187
* their own state.
188188
*
189189
* @return Boolean
190190
*/
191-
function isDisabled();
191+
function isReadOnly();
192192

193193
/**
194194
* Returns whether the form is empty.

src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,36 +1231,6 @@ public function testHidden()
12311231
);
12321232
}
12331233

1234-
public function testReadOnly()
1235-
{
1236-
$form = $this->factory->createNamed('text', 'name', null, array(
1237-
'read_only' => true,
1238-
));
1239-
1240-
$this->assertWidgetMatchesXpath($form->createView(), array(),
1241-
'/input
1242-
[@type="text"]
1243-
[@name="name"]
1244-
[@readonly="readonly"]
1245-
'
1246-
);
1247-
}
1248-
1249-
public function testDisabled()
1250-
{
1251-
$form = $this->factory->createNamed('text', 'name', null, array(
1252-
'disabled' => true,
1253-
));
1254-
1255-
$this->assertWidgetMatchesXpath($form->createView(), array(),
1256-
'/input
1257-
[@type="text"]
1258-
[@name="name"]
1259-
[@disabled="disabled"]
1260-
'
1261-
);
1262-
}
1263-
12641234
public function testInteger()
12651235
{
12661236
$form = $this->factory->createNamed('integer', 'name', 123);

src/Symfony/Component/Form/Tests/Extension/Core/Type/FieldTypeTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ public function testPassRequiredAsOption()
6464
$this->assertTrue($form->isRequired());
6565
}
6666

67-
public function testPassDisabledAsOption()
67+
public function testPassReadOnlyAsOption()
6868
{
69-
$form = $this->factory->create('field', null, array('disabled' => true));
69+
$form = $this->factory->create('field', null, array('read_only' => true));
7070

71-
$this->assertTrue($form->isDisabled());
71+
$this->assertTrue($form->isReadOnly());
7272
}
7373

7474
public function testBoundDataIsTrimmedBeforeTransforming()

src/Symfony/Component/Form/Tests/FormFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ public function testUnknownOptions()
616616

617617
$this->setExpectedException('Symfony\Component\Form\Exception\InvalidOptionException',
618618
'The options "invalid", "unknown" do not exist. Known options are: ' .
619-
'"attr", "by_reference", "data", "data_class", "disabled", ' .
619+
'"attr", "by_reference", "data", "data_class", ' .
620620
'"empty_data", "error_bubbling", "error_mapping", "invalid_message", ' .
621621
'"invalid_message_parameters", "label", "max_length", "pattern", ' .
622622
'"property_path", "read_only", "required", "translation_domain", ' .
@@ -633,7 +633,7 @@ public function testUnknownOption()
633633

634634
$this->setExpectedException('Symfony\Component\Form\Exception\InvalidOptionException',
635635
'The option "unknown" does not exist. Known options are: "attr", ' .
636-
'"by_reference", "data", "data_class", "disabled", "empty_data", ' .
636+
'"by_reference", "data", "data_class", "empty_data", ' .
637637
'"error_bubbling", "error_mapping", "invalid_message", ' .
638638
'"invalid_message_parameters", "label", "max_length", "pattern", ' .
639639
'"property_path", "read_only", "required", "translation_domain", ' .

src/Symfony/Component/Form/Tests/FormTest.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ public function testBindForwardsNullIfValueIsMissing()
222222
$this->form->bind(array());
223223
}
224224

225-
public function testBindIsIgnoredIfDisabled()
225+
public function testBindIsIgnoredIfReadOnly()
226226
{
227227
$form = $this->getBuilder()
228-
->setDisabled(true)
228+
->setReadOnly(true)
229229
->setData('initial')
230230
->getForm();
231231

@@ -265,34 +265,34 @@ public function testNotRequired()
265265
$this->assertFalse($child->isRequired());
266266
}
267267

268-
public function testAlwaysDisabledIfParentDisabled()
268+
public function testAlwaysReadOnlyIfParentReadOnly()
269269
{
270-
$parent = $this->getBuilder()->setDisabled(true)->getForm();
271-
$child = $this->getBuilder()->setDisabled(false)->getForm();
270+
$parent = $this->getBuilder()->setReadOnly(true)->getForm();
271+
$child = $this->getBuilder()->setReadOnly(false)->getForm();
272272

273273
$child->setParent($parent);
274274

275-
$this->assertTrue($child->isDisabled());
275+
$this->assertTrue($child->isReadOnly());
276276
}
277277

278-
public function testDisabled()
278+
public function testReadOnly()
279279
{
280-
$parent = $this->getBuilder()->setDisabled(false)->getForm();
281-
$child = $this->getBuilder()->setDisabled(true)->getForm();
280+
$parent = $this->getBuilder()->setReadOnly(false)->getForm();
281+
$child = $this->getBuilder()->setReadOnly(true)->getForm();
282282

283283
$child->setParent($parent);
284284

285-
$this->assertTrue($child->isDisabled());
285+
$this->assertTrue($child->isReadOnly());
286286
}
287287

288-
public function testNotDisabled()
288+
public function testNotReadOnly()
289289
{
290-
$parent = $this->getBuilder()->setDisabled(false)->getForm();
291-
$child = $this->getBuilder()->setDisabled(false)->getForm();
290+
$parent = $this->getBuilder()->setReadOnly(false)->getForm();
291+
$child = $this->getBuilder()->setReadOnly(false)->getForm();
292292

293293
$child->setParent($parent);
294294

295-
$this->assertFalse($child->isDisabled());
295+
$this->assertFalse($child->isReadOnly());
296296
}
297297

298298
public function testCloneChildren()
@@ -371,23 +371,23 @@ public function testValidIfBound()
371371
$this->assertTrue($this->form->isValid());
372372
}
373373

374-
public function testValidIfBoundAndDisabled()
374+
public function testValidIfBoundAndReadOnly()
375375
{
376-
$form = $this->getBuilder()->setDisabled(true)->getForm();
376+
$form = $this->getBuilder()->setReadOnly(true)->getForm();
377377
$form->bind('foobar');
378378

379379
$this->assertTrue($form->isValid());
380380
}
381381

382-
public function testValidIfBoundAndDisabledWithChildren()
382+
public function testValidIfBoundAndReadOnlyWithChildren()
383383
{
384384
$this->factory->expects($this->once())
385385
->method('createNamedBuilder')
386386
->with('text', 'name', null, array())
387387
->will($this->returnValue($this->getBuilder('name')));
388388

389389
$form = $this->getBuilder('person')
390-
->setDisabled(true)
390+
->setReadOnly(true)
391391
->add('name', 'text')
392392
->getForm();
393393
$form->bind(array('name' => 'Jacques Doe'));

0 commit comments

Comments
 (0)
0