-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[TwigBridge] Handle form label attributes like others #20365
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
Conversation
Something wrong happen with PR title |
@@ -1,10 +1,2 @@ | |||
<?php if (!empty($id)): ?>id="<?php echo $view->escape($id) ?>" <?php endif ?> | |||
<?php foreach ($attr as $k => $v): ?> | |||
<?php if (in_array($v, array('placeholder', 'title'), true)): ?> |
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.
Bug :)
@@ -1,10 +1,2 @@ | |||
id="<?php echo $view->escape($id) ?>" name="<?php echo $view->escape($full_name) ?>" <?php if ($disabled): ?>disabled="disabled" <?php endif ?> | |||
<?php foreach ($attr as $k => $v): ?> | |||
<?php if (in_array($v, array('placeholder', 'title'), true)): ?> |
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.
Also bug :)
👍 |
@fabpot any chance to get this on the 3.2 train? It allows the To clarify this is consistent with |
There will be 3.2.1 after 3.2.0 :) |
That is true 👍 the RC release triggered me that maybe this was forgotten / overlooked at 👼 |
We work around it till 3.3 then :) the 2 bugs are real though.. but i should separate them for 2.7 i just realized. 👍 |
@@ -242,7 +242,7 @@ | |||
{% set label = name|humanize %} | |||
{%- endif -%} | |||
{%- endif -%} | |||
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}</label> | |||
<label{% if label_attr %} {% set attr = label_attr %}{{ block('attributes') }}{% endif %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}</label> |
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.
use {% with %}
around the block rendering instead of assigning label_attr
to attr
, which swallows the original attr variable and could cause issues
…ttributes (ro0NL) This PR was merged into the 2.7 branch. Discussion ---------- [FrameworkBundle] Fix PHP form templates on translatable attributes | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20365 (comment) | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> Separated from #20365 Commits ------- 10806e0 [FrameworkBundle] Fix PHP form templates on translatable attributes
…ttributes (ro0NL) This PR was merged into the 2.7 branch. Discussion ---------- [FrameworkBundle] Fix PHP form templates on translatable attributes | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony/symfony#20365 (comment) | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> Separated from #20365 Commits ------- 10806e0 [FrameworkBundle] Fix PHP form templates on translatable attributes
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.
👍 with minor comments
@@ -1 +1,9 @@ | |||
<?php echo $view['form']->block($form, 'widget_attributes') ?> | |||
<?php foreach ($attr as $k => $v): ?> | |||
<?php if (in_array($k, array('placeholder', 'title'), true)): ?> |
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 think it's worth doing a micro optim here and turn this into:
if ('placeholder' === $k || 'title' === $k):
<?php foreach ($attr as $k => $v): ?> | ||
<?php if (in_array($k, array('placeholder', 'title'), true)): ?> | ||
<?php printf('%s="%s" ', $view->escape($k), $view->escape(false !== $translation_domain ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?> | ||
<?php elseif ($v === true): ?> |
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.
yoda style (same below)
Updated. I qualify it a feature, not a bug. |
Thank you @ro0NL. |
…ributes (craue) This PR was merged into the 3.3 branch. Discussion ---------- [Form][3.3] avoid double blanks while rendering form attributes | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | kind of | New feature? | no | BC breaks? | no (rather reverts one) | Deprecations? | no | Tests pass? | we'll see | Fixed tickets | -- | License | MIT | Doc PR | -- This fix avoids the double blanks introduced by #20365 when using the Twig template. The `attributes` block already renders one blank before each attribute, so there's no need to add another one prior to calling the block. Commits ------- a9c11c9 avoid double blanks while rendering form attributes
The HTML for rendering attributes is duplicated in multiple blocks, making it error prone/hard to maintain.
Next, the label attributes followed a different approach. Imo. all should follow the same base rendering, showing the above is actually an issue.