Skip to content

Do not put any empty div if label is disabled #19247

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

{% block form_label -%}
{% spaceless %}
{% if label is same as(false) %}
<div class="{{ block('form_label_class') }}"></div>
{% else %}
{% if label is not same as(false) %}
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ block('form_label_class'))|trim}) %}
{{- parent() -}}
{% endif %}
Expand Down Expand Up @@ -77,5 +75,9 @@ col-sm-2
{% endblock reset_row %}

{% block form_group_class -%}
col-sm-10
{%- if label is same as(false) -%}
col-sm-12
{%- else -%}
col-sm-10
{%- endif -%}
{%- endblock form_group_class %}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ public function testLabelWithCustomTextAsOptionAndCustomAttributesPassedDirectly
);
}

public function testLabelNoDivIfFalse()
{
$this->assertEmpty(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could use a consistent style here:

$view = $this->factory->createNamed('name', 'date', null, array('label' => false))->createView();

$this->assertEmpty($this->renderLabel($view), 'The label should not be rendered');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly don't see the interest. You create a variable that will be used only once.

Why not simply pass the result to the function?

Copy link
Contributor

@greg0ire greg0ire Sep 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I second that. See more information about thoughtless one-time variables here. Note that OTVs can be used to break down complicated expressions, but I personally don't feel this is complicated enough to warrant an OTV.

If you need the variable because it clarifies things, maybe consider using a comment instead, you can even write whole sentences with them.

$this->renderLabel(
$this->factory->createNamed('name', 'date', null, array('label' => false))->createView()
),
'The label should not be rendered'
);
}

public function testStartTag()
{
$form = $this->factory->create('form', null, array(
Expand Down