From 2399e736a02f06e9aa7b7b27f37674f469ffbfd4 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Sun, 30 Oct 2016 09:38:11 +0000 Subject: [PATCH 1/2] [Form] Consistent HTML attribute rendering --- .../views/Form/form_div_layout.html.twig | 37 +++---------------- .../Resources/views/Form/attributes.html.php | 10 ++++- .../views/Form/button_attributes.html.php | 12 +----- .../Resources/views/Form/form_label.html.php | 2 +- .../views/Form/widget_attributes.html.php | 10 +---- .../Form/widget_container_attributes.html.php | 12 +----- 6 files changed, 20 insertions(+), 63 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig index e1d09153dfe60..64377bb9f7d09 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig @@ -79,7 +79,7 @@ {{- block('choice_widget_options') -}} {%- else -%} - + {%- endif -%} {% endfor %} {%- endblock choice_widget_options -%} @@ -242,7 +242,7 @@ {% set label = name|humanize %} {%- endif -%} {%- endif -%} - {{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }} + {{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }} {%- endif -%} {%- endblock form_label -%} @@ -334,44 +334,17 @@ id="{{ id }}" name="{{ full_name }}" {%- if disabled %} disabled="disabled"{% endif -%} {%- if required %} required="required"{% endif -%} - {%- for attrname, attrvalue in attr -%} - {{- " " -}} - {%- if attrname in ['placeholder', 'title'] -%} - {{- attrname }}="{{ translation_domain is same as(false) ? attrvalue : attrvalue|trans({}, translation_domain) }}" - {%- elseif attrvalue is same as(true) -%} - {{- attrname }}="{{ attrname }}" - {%- elseif attrvalue is not same as(false) -%} - {{- attrname }}="{{ attrvalue }}" - {%- endif -%} - {%- endfor -%} + {{ block('attributes') }} {%- endblock widget_attributes -%} {%- block widget_container_attributes -%} {%- if id is not empty %}id="{{ id }}"{% endif -%} - {%- for attrname, attrvalue in attr -%} - {{- " " -}} - {%- if attrname in ['placeholder', 'title'] -%} - {{- attrname }}="{{ translation_domain is same as(false) ? attrvalue : attrvalue|trans({}, translation_domain) }}" - {%- elseif attrvalue is same as(true) -%} - {{- attrname }}="{{ attrname }}" - {%- elseif attrvalue is not same as(false) -%} - {{- attrname }}="{{ attrvalue }}" - {%- endif -%} - {%- endfor -%} + {{ block('attributes') }} {%- endblock widget_container_attributes -%} {%- block button_attributes -%} id="{{ id }}" name="{{ full_name }}"{% if disabled %} disabled="disabled"{% endif -%} - {%- for attrname, attrvalue in attr -%} - {{- " " -}} - {%- if attrname in ['placeholder', 'title'] -%} - {{- attrname }}="{{ translation_domain is same as(false) ? attrvalue : attrvalue|trans({}, translation_domain) }}" - {%- elseif attrvalue is same as(true) -%} - {{- attrname }}="{{ attrname }}" - {%- elseif attrvalue is not same as(false) -%} - {{- attrname }}="{{ attrvalue }}" - {%- endif -%} - {%- endfor -%} + {{ block('attributes') }} {%- endblock button_attributes -%} {% block attributes -%} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/attributes.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/attributes.html.php index eb421be817691..fa74919d42ea3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/attributes.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/attributes.html.php @@ -1 +1,9 @@ -block($form, 'widget_attributes') ?> + $v): ?> + +escape($k), $view->escape(false !== $translation_domain ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?> + +escape($k), $view->escape($k)) ?> + +escape($k), $view->escape($v)) ?> + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/button_attributes.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/button_attributes.html.php index 56b3dd92846d3..279233baa3fc0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/button_attributes.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/button_attributes.html.php @@ -1,10 +1,2 @@ -id="escape($id) ?>" name="escape($full_name) ?>" disabled="disabled" - $v): ?> - -escape($k), $view->escape(false !== $translation_domain ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?> - -escape($k), $view->escape($k)) ?> - -escape($k), $view->escape($v)) ?> - - +id="escape($id) ?>" name="escape($full_name) ?>" disabled="disabled" +block($form, 'attributes') : '' ?> diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_label.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_label.html.php index 7a51b2ce7b4ff..78c953ec5a1f3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_label.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_label.html.php @@ -4,5 +4,5 @@ $name, '%id%' => $id)) : $view['form']->humanize($name); } ?> - +block($form, 'attributes', array('attr' => $label_attr)); } ?>>escape(false !== $translation_domain ? $view['translator']->trans($label, array(), $translation_domain) : $label) ?> diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget_attributes.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget_attributes.html.php index 3fefa47c15c99..41c0cc7bfe8ba 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget_attributes.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget_attributes.html.php @@ -1,11 +1,3 @@ id="escape($id) ?>" name="escape($full_name) ?>" disabled="disabled" required="required" - $v): ?> - -escape($k), $view->escape(false !== $translation_domain ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?> - -escape($k), $view->escape($k)) ?> - -escape($k), $view->escape($v)) ?> - - +block($form, 'attributes') : '' ?> diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget_container_attributes.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget_container_attributes.html.php index c4dff7b61f4e0..fdd176d12c79f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget_container_attributes.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget_container_attributes.html.php @@ -1,10 +1,2 @@ -id="escape($id) ?>" - $v): ?> - -escape($k), $view->escape(false !== $translation_domain ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?> - -escape($k), $view->escape($k)) ?> - -escape($k), $view->escape($v)) ?> - - +id="escape($id) ?>" +block($form, 'attributes') : '' ?> From 71e6ece8cdf50eae42f56f56dedf943905db0c68 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Thu, 29 Dec 2016 13:46:32 +0100 Subject: [PATCH 2/2] Update attributes.html.php --- .../Resources/views/Form/attributes.html.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/attributes.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/attributes.html.php index fa74919d42ea3..a9bd62f2a1b9e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/attributes.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/attributes.html.php @@ -1,9 +1,9 @@ $v): ?> - + escape($k), $view->escape(false !== $translation_domain ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?> - + escape($k), $view->escape($k)) ?> - + escape($k), $view->escape($v)) ?>