Skip to content

Commit 052168f

Browse files
committed
[Form] use attr[readonly] instead of read_only option
1 parent 7284680 commit 052168f

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@
314314

315315
{%- block widget_attributes -%}
316316
id="{{ id }}" name="{{ full_name }}"
317-
{%- if read_only %} readonly="readonly"{% endif -%}
318317
{%- if disabled %} disabled="disabled"{% endif -%}
319318
{%- if required %} required="required"{% endif -%}
320319
{%- for attrname, attrvalue in attr -%}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
id="<?php echo $view->escape($id) ?>" name="<?php echo $view->escape($full_name) ?>" <?php if ($read_only): ?>readonly="readonly" <?php endif ?>
2-
<?php if ($disabled): ?>disabled="disabled" <?php endif ?>
3-
<?php if ($required): ?>required="required" <?php endif ?>
1+
id="<?php echo $view->escape($id) ?>" name="<?php echo $view->escape($full_name) ?>"
2+
<?php if ($disabled): ?> disabled="disabled"<?php endif ?>
3+
<?php if ($required): ?> required="required"<?php endif ?>
44
<?php foreach ($attr as $k => $v): ?>
55
<?php if (in_array($k, array('placeholder', 'title'), true)): ?>
6-
<?php printf('%s="%s" ', $view->escape($k), $view->escape($view['translator']->trans($v, array(), $translation_domain))) ?>
6+
<?php printf(' %s="%s"', $view->escape($k), $view->escape($view['translator']->trans($v, array(), $translation_domain))) ?>
77
<?php elseif ($v === true): ?>
8-
<?php printf('%s="%s" ', $view->escape($k), $view->escape($k)) ?>
8+
<?php printf(' %s="%s"', $view->escape($k), $view->escape($k)) ?>
99
<?php elseif ($v !== false): ?>
10-
<?php printf('%s="%s" ', $view->escape($k), $view->escape($v)) ?>
10+
<?php printf(' %s="%s"', $view->escape($k), $view->escape($v)) ?>
1111
<?php endif ?>
1212
<?php endforeach ?>

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,20 @@ public function buildView(FormView $view, FormInterface $form, array $options)
7171
parent::buildView($view, $form, $options);
7272

7373
$name = $form->getName();
74-
$readOnly = $options['read_only'];
7574

7675
if ($view->parent) {
7776
if ('' === $name) {
7877
throw new LogicException('Form node with empty name can be used only as root form node.');
7978
}
8079

8180
// Complex fields are read-only if they themselves or their parents are.
82-
if (!$readOnly) {
83-
$readOnly = $view->parent->vars['read_only'];
81+
if (!isset($view->vars['attr']['readonly']) && isset($view->parent->vars['attr']['readonly']) && false !== $view->parent->vars['attr']['readonly'])) {
82+
$view->vars['attr']['readonly'] = true;
8483
}
8584
}
8685

8786
$view->vars = array_replace($view->vars, array(
88-
'read_only' => $readOnly,
87+
'read_only' => isset($view->vars['attr']['readonly']) && false !== $view->vars['attr']['readonly'], // deprecated
8988
'errors' => $form->getErrors(),
9089
'valid' => $form->isSubmitted() ? $form->isValid() : true,
9190
'value' => $form->getViewData(),
@@ -185,6 +184,15 @@ public function configureOptions(OptionsResolver $resolver)
185184
return $attributes;
186185
};
187186

187+
// BC for "read_only" option
188+
$attrNormalizer = function (Options $options, array $attr) {
189+
if (!isset($attr['readonly']) && $options['read_only']) {
190+
$attr['readonly'] = true;
191+
}
192+
193+
return $attr;
194+
};
195+
188196
$readOnlyNormalizer = function (Options $options, $readOnly) {
189197
if (null !== $readOnly) {
190198
trigger_error('The form option "read_only" is deprecated since version 2.7 and will be removed in 3.0. Use "attr[\'readonly\']" instead.', E_USER_DEPRECATED);
@@ -200,7 +208,7 @@ public function configureOptions(OptionsResolver $resolver)
200208
'empty_data' => $emptyData,
201209
'trim' => true,
202210
'required' => true,
203-
'read_only' => null,
211+
'read_only' => null, // deprecated
204212
'max_length' => null,
205213
'pattern' => null,
206214
'property_path' => null,
@@ -219,6 +227,7 @@ public function configureOptions(OptionsResolver $resolver)
219227
'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.',
220228
));
221229

230+
$resolver->setNormalizer('attr', $attrNormalizer);
222231
$resolver->setNormalizer('read_only', $readOnlyNormalizer);
223232

224233
$resolver->setAllowedTypes('label_attr', 'array');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy