8000 [Form][TwigBridge] Add help_html by mpiot · Pull Request #29861 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

8000 [Form][TwigBridge] Add help_html #29861

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

Merged
merged 1 commit into from
Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
8000
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Bridge/Twig/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

4.3.0
-----

* add `help_html` form option to display the `help` text as HTML

4.2.0
-----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,17 @@
{%- set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ ' help-block')|trim}) -%}
<span id="{{ id }}_help"{% with { attr: help_attr } %}{{ block('attributes') }}{% endwith %}>
{%- if translation_domain is same as(false) -%}
{{- help -}}
{%- if help_html is same as(false) -%}
{{- help -}}
{%- else -%}
{{- help|raw -}}
{%- endif -%}
{%- else -%}
{{- help|trans({}, translation_domain) -}}
{%- if help_html is same as(false) -%}
{{- help|trans({}, translation_domain) -}}
{%- else -%}
{{- help|trans({}, translation_domain)|raw -}}
{%- endif -%}
{%- endif -%}
</span>
{%- endif -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,17 @@
{%- set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ ' form-text text-muted')|trim}) -%}
<small id="{{ id }}_help"{% with { attr: help_attr } %}{{ block('attributes') }}{% endwith %}>
{%- if translation_domain is same as(false) -%}
{{- help -}}
{%- if help_html is same as(false) -%}
{{- help -}}
{%- else -%}
{{- help|raw -}}
{%- endif -%}
{%- else -%}
{{- help|trans({}, translation_domain) -}}
{%- if help_html is same as(false) -%}
{{- help|trans({}, translation_domain) -}}
{%- else -%}
{{- help|trans({}, translation_domain)|raw -}}
{%- endif -%}
{%- endif -%}
</small>
{%- endif -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,17 @@
{%- set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ ' help-text')|trim}) -%}
<p id="{{ id }}_help"{% with { attr: help_attr } %}{{ block('attributes') }}{% endwith %}>
{%- if translation_domain is same as(false) -%}
{{- help -}}
{%- if help_html is same as(false) -%}
{{- help -}}
{%- else -%}
{{- help|raw -}}
{%- endif -%}
{%- else -%}
{{- help|trans({}, translation_domain) -}}
{%- if help_html is same as(false) -%}
{{- help|trans({}, translation_domain) -}}
{%- else -%}
{{- help|trans({}, translation_domain)|raw -}}
{%- endif -%}
{%- endif -%}
</p>
{%- endif -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,89 @@ public function testHelpAttr()
);
}

public function testHelpHtmlDefaultIsFalse()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'help' => 'Help <b>text</b> test!',
]);

$view = $form->createView();
$html = $this->renderHelp($view);

$this->assertMatchesXpath($html,
'/span
[@id="name_help"]
[@class="help-block"]
[.="[trans]Help <b>text</b> test![/trans]"]
'
);

$this->assertMatchesXpath($html,
'/span
[@id="name_help"]
[@class="help-block"]
/b
[.="text"]
', 0
);
}

public function testHelpHtmlIsFalse()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'help' => 'Help <b>text</b> test!',
'help_html' => false,
]);

$view = $form->createView();
$html = $this->renderHelp($view);

$this->assertMatchesXpath($html,
'/span
[@id="name_help"]
[@class="help-block"]
[.="[trans]Help <b>text</b> test![/trans]"]
'
);

$this->assertMatchesXpath($html,
'/span
[@id="name_help"]
[@class="help-block"]
/b
[.="text"]
', 0
);
}

public function testHelpHtmlIsTrue()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'help' => 'Help <b>text</b> test!',
'help_html' => true,
]);

$view = $form->createView();
$html = $this->renderHelp($view);

$this->assertMatchesXpath($html,
'/span
[@id="name_help"]
[@class="help-block"]
[.="[trans]Help <b>text</b> test![/trans]"]
', 0
);

$this->assertMatchesXpath($html,
'/span
[@id="name_help"]
[@class="help-block"]
/b
[.="text"]
'
);
}

public function testErrors()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,89 @@ public function testHelpAttr()
);
}

public function testHelpHtmlDefaultIsFalse()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'help' => 'Help <b>text</b> test!',
]);

$view = $form->createView();
$html = $this->renderHelp($view);

$this->assertMatchesXpath($html,
'/small
[@id="name_help"]
[@class="form-text text-muted"]
[.="[trans]Help <b>text</b> test![/trans]"]
'
);

$this->assertMatchesXpath($html,
'/small
[@id="name_help"]
[@class="form-text text-muted"]
/b
[.="text"]
', 0
);
}

public function testHelpHtmlIsFalse()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'help' => 'Help <b>text</b> test!',
'help_html' => false,
]);

$view = $form->createView();
$html = $this->renderHelp($view);

$this->assertMatchesXpath($html,
'/small
[@id="name_help"]
[@class="form-text text-muted"]
[.="[trans]Help <b>text</b> test![/trans]"]
'
);

$this->assertMatchesXpath($html,
'/small
[@id="name_help"]
[@class="form-text text-muted"]
/b
[.="text"]
', 0
);
}

public function testHelpHtmlIsTrue()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'help' => 'Help <b>text</b> test!',
'help_html' => true,
]);

$view = $form->createView();
$html = $this->renderHelp($view);

$this->assertMatchesXpath($html,
'/small
[@id="name_help"]
[@class="form-text text-muted"]
[.="[trans]Help <b>text</b> test![/trans]"]
', 0
);

$this->assertMatchesXpath($html,
'/small
[@id="name_help"]
[@class="form-text text-muted"]
/b
[.="text"]
'
);
}

public function testErrors()
{
$form = $this->factory->createNamed('name', TextType::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,89 @@ public function testHelpAttr()
);
}

public function testHelpHtmlDefaultIsFalse()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'help' => 'Help <b>text</b> test!',
]);

$view = $form->createView();
$html = $this->renderHelp($view);

$this->assertMatchesXpath($html,
'/p
[@id="name_help"]
[@class="help-text"]
[.="[trans]Help <b>text</b> test![/trans]"]
'
);

$this->assertMatchesXpath($html,
'/p
[@id="name_help"]
[@class="help-text"]
/b
[.="text"]
', 0
);
}

public function testHelpHtmlIsFalse()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'help' => 'Help <b>text</b> test!',
'help_html' => false,
]);

$view = $form->createView();
$html = $this->renderHelp($view);

$this->assertMatchesXpath($html,
'/p
[@id="name_help"]
[@class="help-text"]
[.="[trans]Help <b>text</b> test![/trans]"]
'
);

$this->assertMatchesXpath($html,
'/p
[@id="name_help"]
[@class="help-text"]
/b
[.="text"]
', 0
);
}

public function testHelpHtmlIsTrue()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'help' => 'Help <b>text</b> test!',
'help_html' => true,
]);

$view = $form->createView();
$html = $this->renderHelp($view);

$this->assertMatchesXpath($html,
'/p
[@id="name_help"]
[@class="help-text"]
[.="[trans]Help <b>text</b> test![/trans]"]
', 0
);

$this->assertMatchesXpath($html,
'/p
[@id="name_help"]
[@class="help-text"]
/b
[.="text"]
'
);
}

protected function renderForm(FormView $view, array $vars = [])
{
return (string) $this->renderer->renderBlock($view, 'form', $vars);
Expand Down
Loading
0