Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e317e0a

Browse filesBrowse files
ro0NLfabpot
authored andcommitted
[TwigBridge] Handle form label attributes like others
1 parent 64e1da0 commit e317e0a
Copy full SHA for e317e0a

File tree

Expand file treeCollapse file tree

6 files changed

+20
-63
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+20
-63
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
+5-32Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
{{- block('choice_widget_options') -}}
8080
</optgroup>
8181
{%- else -%}
82-
<option value="{{ choice.value }}"{% if choice.attr %} {% set attr = choice.attr %}{{ block('attributes') }}{% endif %}{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice_translation_domain is same as(false) ? choice.label : choice.label|trans({}, choice_translation_domain) }}</option>
82+
<option value="{{ choice.value }}"{% if choice.attr %} {% with { attr: choice.attr } %}{{ block('attributes') }}{% endwith %}{% endif %}{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice_translation_domain is same as(false) ? choice.label : choice.label|trans({}, choice_translation_domain) }}</option>
8383
{%- endif -%}
8484
{% endfor %}
8585
{%- endblock choice_widget_options -%}
@@ -242,7 +242,7 @@
242242
{% set label = name|humanize %}
243243
{%- endif -%}
244244
{%- endif -%}
245-
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}</label>
245+
<label{% if label_attr %} {% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}</label>
246246
{%- endif -%}
247247
{%- endblock form_label -%}
248248

@@ -334,44 +334,17 @@
334334
id="{{ id }}" name="{{ full_name }}"
335335
{%- if disabled %} disabled="disabled"{% endif -%}
336336
{%- if required %} required="required"{% endif -%}
337-
{%- for attrname, attrvalue in attr -%}
338-
{{- " " -}}
339-
{%- if attrname in ['placeholder', 'title'] -%}
340-
{{- attrname }}="{{ translation_domain is same as(false) ? attrvalue : attrvalue|trans({}, translation_domain) }}"
341-
{%- elseif attrvalue is same as(true) -%}
342-
{{- attrname }}="{{ attrname }}"
343-
{%- elseif attrvalue is not same as(false) -%}
344-
{{- attrname }}="{{ attrvalue }}"
345-
{%- endif -%}
346-
{%- endfor -%}
337+
{{ block('attributes') }}
347338
{%- endblock widget_attributes -%}
348339

349340
{%- block widget_container_attributes -%}
350341
{%- if id is not empty %}id="{{ id }}"{% endif -%}
351-
{%- for attrname, attrvalue in attr -%}
352-
{{- " " -}}
353-
{%- if attrname in ['placeholder', 'title'] -%}
354-
{{- attrname }}="{{ translation_domain is same as(false) ? attrvalue : attrvalue|trans({}, translation_domain) }}"
355-
{%- elseif attrvalue is same as(true) -%}
356-
{{- attrname }}="{{ attrname }}"
357-
{%- elseif attrvalue is not same as(false) -%}
358-
{{- attrname }}="{{ attrvalue }}"
359-
{%- endif -%}
360-
{%- endfor -%}
342+
{{ block('attributes') }}
361343
{%- endblock widget_container_attributes -%}
362344

363345
{%- block button_attributes -%}
364346
id="{{ id }}" name="{{ full_name }}"{% if disabled %} disabled="disabled"{% endif -%}
365-
{%- for attrname, attrvalue in attr -%}
366-
{{- " " -}}
367-
{%- if attrname in ['placeholder', 'title'] -%}
368-
{{- attrname }}="{{ translation_domain is same as(false) ? attrvalue : attrvalue|trans({}, translation_domain) }}"
369-
{%- elseif attrvalue is same as(true) -%}
370-
{{- attrname }}="{{ attrname }}"
371-
{%- elseif attrvalue is not same as(false) -%}
372-
{{- attrname }}="{{ attrvalue }}"
373-
{%- endif -%}
374-
{%- endfor -%}
347+
{{ block('attributes') }}
375348
{%- endblock button_attributes -%}
376349

377350
{% block attributes -%}
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
<?php echo $view['form']->block($form, 'widget_attributes') ?>
1+
<?php foreach ($attr as $k => $v): ?>
2+
<?php if ('placeholder' === $k || 'title' === $k): ?>
3+
<?php printf('%s="%s" ', $view->escape($k), $view->escape(false !== $translation_domain ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?>
4+
<?php elseif (true === $v): ?>
5+
<?php printf('%s="%s" ', $view->escape($k), $view->escape($k)) ?>
6+
<?php elseif (false !== $v): ?>
7+
<?php printf('%s="%s" ', $view->escape($k), $view->escape($v)) ?>
8+
<?php endif ?>
9+
<?php endforeach ?>
+2-10Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
1-
id="<?php echo $view->escape($id) ?>" name="<?php echo $view->escape($full_name) ?>" <?php if ($disabled): ?>disabled="disabled" <?php endif ?>
2-
<?php foreach ($attr as $k => $v): ?>
3-
<?php if (in_array($k, array('placeholder', 'title'), true)): ?>
4-
<?php printf('%s="%s" ', $view->escape($k), $view->escape(false !== $translation_domain ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?>
5-
<?php elseif ($v === true): ?>
6-
<?php printf('%s="%s" ', $view->escape($k), $view->escape($k)) ?>
7-
<?php elseif ($v !== false): ?>
8-
<?php printf('%s="%s" ', $view->escape($k), $view->escape($v)) ?>
9-
<?php endif ?>
10-
<?php endforeach ?>
1+
id="<?php echo $view->escape($id) ?>" name="<?php echo $view->escape($full_name) ?>"<?php if ($disabled): ?> disabled="disabled"<?php endif ?>
2+
<?php echo $attr ? ' '.$view['form']->block($form, 'attributes') : '' ?>

‎src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_label.html.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_label.html.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
<?php if (!$label) { $label = isset($label_format)
55
? strtr($label_format, array('%name%' => $name, '%id%' => $id))
66
: $view['form']->humanize($name); } ?>
7-
<label <?php foreach ($label_attr as $k => $v) { printf('%s="%s" ', $view->escape($k), $view->escape($v)); } ?>><?php echo $view->escape(false !== $translation_domain ? $view['translator']->trans($label, array(), $translation_domain) : $label) ?></label>
7+
<label<?php if ($label_attr) { echo ' '.$view['form']->block($form, 'attributes', array('attr' => $label_attr)); } ?>><?php echo $view->escape(false !== $translation_domain ? $view['translator']->trans($label, array(), $translation_domain) : $label) ?></label>
88
<?php endif ?>
+1-9Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
id="<?php echo $view->escape($id) ?>" name="<?php echo $view->escape($full_name) ?>"<?php if ($disabled): ?> disabled="disabled"<?php endif ?>
22
<?php if ($required): ?> required="required"<?php endif ?>
3-
<?php foreach ($attr as $k => $v): ?>
4-
<?php if (in_array($k, array('placeholder', 'title'), true)): ?>
5-
<?php printf(' %s="%s"', $view->escape($k), $view->escape(false !== $translation_domain ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?>
6-
<?php elseif ($v === true): ?>
7-
<?php printf(' %s="%s"', $view->escape($k), $view->escape($k)) ?>
8-
<?php elseif ($v !== false): ?>
9-
<?php printf(' %s="%s"', $view->escape($k), $view->escape($v)) ?>
10-
<?php endif ?>
11-
<?php endforeach ?>
3+
<?php echo $attr ? ' '.$view['form']->block($form, 'attributes') : '' ?>
+2-10Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
1-
<?php if (!empty($id)): ?>id="<?php echo $view->escape($id) ?>" <?php endif ?>
2-
<?php foreach ($attr as $k => $v): ?>
3-
<?php if (in_array($k, array('placeholder', 'title'), true)): ?>
4-
<?php printf('%s="%s" ', $view->escape($k), $view->escape(false !== $translation_domain ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?>
5-
<?php elseif ($v === true): ?>
6-
<?php printf('%s="%s" ', $view->escape($k), $view->escape($k)) ?>
7-
<?php elseif ($v !== false): ?>
8-
<?php printf('%s="%s" ', $view->escape($k), $view->escape($v)) ?>
9-
<?php endif ?>
10-
<?php endforeach ?>
1+
<?php if (!empty($id)): ?>id="<?php echo $view->escape($id) ?>"<?php endif ?>
2+
<?php echo $attr ? ' '.$view['form']->block($form, 'attributes') : '' ?>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.