8000 Add a data_help method in Form by mpiot · Pull Request #26332 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Add a data_help method in Form #26332

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 35 commits into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c8914f5
Add a data_help method in Form
Feb 27, 2018
1b89f9d
Add a template fot div_layout
Feb 27, 2018
8b97c1b
Use a shortcut to acces help var in Twig template
Feb 27, 2018
e311838
Remove raw filter for help
Feb 27, 2018
831693a
Add trans filter
Feb 27, 2018
2c2c045
Adapt existant tests
Feb 27, 2018
d3e3e49
Fix: check translation domain
Feb 27, 2018
067c681
Template for table, Foundation and Bootstrap 3
Feb 28, 2018
8094804
Add Tests
Feb 28, 2018
c934e49
Add test without help set
Feb 28, 2018
f15bc79
Fix coding standards
Feb 28, 2018
4f2581d
Use array long syntax
Feb 28, 2018
ba798df
FrameworkBundle Tests
Feb 28, 2018
6ea7a20
Remove vars option from form_help
Feb 28, 2018
058489d
Add an id to the help
Mar 1, 2018
1f3a15e
Rename id
Mar 1, 2018
bf4d08c
Add aria-describedBy on input
Mar 1, 2018
30deaa9
PSR fix
Mar 1, 2018
77fa317
Fix Test
Mar 1, 2018
f948147
Rename help 8000 id (snake_case)
Mar 1, 2018
aada72c
Set help option on nul as default
Mar 1, 2018
edb95f8
Use array long syntax
Mar 1, 2018
98065d3
fabpot.io fix
Mar 1, 2018
fd53bc5
Enable aria-described in row for all Templates
Mar 1, 2018
69ded67
Added form_help on horizontal design and removed special variable
Nyholm Mar 18, 2018
f1d13a8
Fix Fabpot.io
mpiot Mar 20, 2018
075fcfd
[FrameworkBundle] Add widgetAtt to formTable/form_row
mpiot Mar 20, 2018
d84be70
Update composer files
mpiot Mar 21, 2018
437b77e
Skip renderHelp test as skipped if not override
mpiot Mar 21, 2018
32bf1f6
Test the renderHelp method in all Tests about help to skip them if ne…
mpiot Mar 21, 2018
8b937ff
Try without try/catch
mpiot Mar 21, 2018
c74e0dc
Use spaceless balises in Twig templates
mpiot Mar 22, 2018
d723756
Fix some mistakes
mpiot Mar 23, 2018
859ee03
Revert: remove comment line from twig templates
mpiot Mar 23, 2018
585ca28
Add return type hint
mpiot Mar 23, 2018
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
1 change: 1 addition & 0 deletions src/Symfony/Bridge/Twig/Extension/FormExtension.php
10000
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function getFunctions()
new TwigFunction('form_widget', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
new TwigFunction('form_errors', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
new TwigFunction('form_label', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
new TwigFunction('form_help', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
new TwigFunction('form_row', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
new TwigFunction('form_rest', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
new TwigFunction('form', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ col-sm-2
{# Rows #}

{% block form_row -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
{{- form_label(form) -}}
<div class="{{ block('form_group_class') }}">
{{- form_widget(form) -}}
{{- form_widget(form, widget_attr) -}}
{{- form_help(form) -}}
{{- form_errors(form) -}}
</div>
{##}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@
{# Rows #}

{% block form_row -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
{{- form_label(form) -}}
{{- form_widget(form) -}}
{{- form_widget(form, widget_attr) -}}
{{- form_help(form) -}}
{{- form_errors(form) -}}
</div>
{%- endblock form_row %}
Expand Down Expand Up @@ -149,3 +154,17 @@
{% if form is not rootform %}</span>{% else %}</div>{% endif %}
{%- endif %}
{%- endblock form_errors %}

{# Help #}

{% block form_help -%}
{%- if help is not empty -%}
<span id="{{ id }}_help" class="help-block">
{%- if translation_domain is same as(false) -%}
{{- help -}}
{%- else -%}
{{- help|trans({}, translation_domain) -}}
{%- endif -%}
</span>
{%- endif -%}
{%- endblock form_help %}
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,31 @@ col-sm-2
{%- if expanded is defined and expanded -%}
{{ block('fieldset_form_row') }}
{%- else -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<div class="form-group row{% if (not compound or force_error|default(false)) and not valid %} is-invalid{% endif %}">
{{- form_label(form) -}}
<div class="{{ block('form_group_class') }}">
{{- form_widget(form) -}}
{{- form_widget(form, widget_attr) -}}
{{- form_help(form) -}}
</div>
{##}</div>
{%- endif -%}
{%- endblock form_row %}

{% block fieldset_form_row -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<fieldset class="form-group">
<div class="row{% if (not compound or force_error|default(false)) and not valid %} is-invalid{% endif %}">
{{- form_label(form) -}}
<div class="{{ block('form_group_class') }}">
{{- form_widget(form) -}}
{{- form_widget(form, widget_attr) -}}
{{- form_help(form) -}}
</div>
</div>
{##}</fieldset>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,14 @@
{%- if compound is defined and compound -%}
{%- set element = 'fieldset' -%}
{%- endif -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<{{ element|default('div') }} class="form-group">
{{- form_label(form) -}}
{{- form_widget(form) -}}
{{- form_widget(form, widget_attr) -}}
{{- form_help(form) -}}
</{{ element|default('div') }}>
{%- endblock form_row %}

Expand All @@ -276,3 +281,17 @@
</span>
{%- endif %}
{%- endblock form_errors %}

{# Help #}

{% block form_help -%}
{%- if help is not empty -%}
<small id="{{ id }}_help" class="form-text text-muted">
{%- if translation_domain is same as(false) -%}
{{- help -}}
{%- else -%}
{{- help|trans({}, translation_domain) -}}
{%- endif -%}
</small>
{%- endif -%}
{%- endblock form_help %}
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,20 @@

{%- block button_label -%}{%- endblock -%}

{# Help #}

{% block form_help -%}
{%- if help is not empty -%}
<p id="{{ id }}_help" class="help-text">
{%- if translation_domain is same as(false) -%}
{{- help -}}
{%- else -%}
{{- help|trans({}, translation_domain) -}}
{%- endif -%}
</p>
{%- endif -%}
{%- endblock form_help %}

{# Rows #}

{%- block repeated_row -%}
Expand All @@ -298,10 +312,15 @@
{%- endblock repeated_row -%}

{%- block form_row -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<div>
{{- form_label(form) -}}
{{- form_errors(form) -}}
{{- form_widget(form) -}}
{{- form_widget(form, widget_attr) -}}
{{- form_help(form) -}}
</div>
{%- endblock form_row -%}

Expand Down
7 changes: 6 additions & 1 deletion src/Symfony/Bridge/Twig/Resources/views/Form/form_table_layout.html.twig
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
{% use "form_div_layout.html.twig" %}

{%- block form_row -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<tr>
<td>
{{- form_label(form) -}}
</td>
<td>
{{- form_errors(form) -}}
{{- form_widget(form) -}}
{{- form_widget(form, widget_attr) -}}
{{- form_help(form) -}}
</td>
</tr>
{%- endblock form_row -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,16 @@
{# Rows #}

{% block form_row -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<div class="row">
<div class="large-12 columns{% if (not compound or force_error|default(false)) and not valid %} error{% endif %}">
{{ form_label(form) }}
{{ form_widget(form) }}
{{ form_errors(form) }}
{{- form_label(form) -}}
{{- form_widget(form, widget_attr) -}}
{{- form_help(form) -}}
{{- form_errors(form) -}}
</div>
</div>
{%- endblock form_row %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ protected function renderLabel(FormView $view, $label = null, array $vars = arra
return (string) $this->renderer->searchAndRenderBlock($view, 'label', $vars);
}

protected function renderHelp(FormView $view)
{
return (string) $this->renderer->searchAndRenderBlock($view, 'help');
}

protected function renderErrors(FormView $view)
{
return (string) $this->renderer->searchAndRenderBlock($view, 'errors');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ protected function renderLabel(FormView $view, $label = null, array $vars = arra
return (string) $this->renderer->searchAndRenderBlock($view, 'label', $vars);
}

protected function renderHelp(FormView $view)
{
return (string) $this->renderer->searchAndRenderBlock($view, 'help');
}

protected function renderErrors(FormView $view)
{
return (string) $this->renderer->searchAndRenderBlock($view, 'errors');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ protected function renderLabel(FormView $view, $label = null, array $vars = arra
return (string) $this->renderer->searchAndRenderBlock($view, 'label', $vars);
}

protected function renderHelp(FormView $view)
{
return (string) $this->renderer->searchAndRenderBlock($view, 'help');
}

protected function renderErrors(FormView $view)
{
return (string) $this->renderer->searchAndRenderBlock($view, 'errors');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ protected function renderLabel(FormView $view, $label = null, array $vars = arra
return (string) $this->renderer->searchAndRenderBlock($view, 'label', $vars);
}

protected function renderHelp(FormView $view)
{
return (string) $this->renderer->searchAndRenderBlock($view, 'help');
}

protected function renderErrors(FormView $view)
{
return (string) $this->renderer->searchAndRenderBlock($view, 'errors');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ protected function renderLabel(FormView $view, $label = null, array $vars = arra
return (string) $this->renderer->searchAndRenderBlock($view, 'label', $vars);
}

protected function renderHelp(FormView $view)
{
return (string) $this->renderer->searchAndRenderBlock($view, 'help');
}

protected function renderErrors(FormView $view)
{
return (string) $this->renderer->searchAndRenderBlock($view, 'errors');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ protected function renderLabel(FormView $view, $label = null, array $vars = arra
return (string) $this->renderer->searchAndRenderBlock($view, 'label', $vars);
}

protected function renderHelp(FormView $view)
{
return (string) $this->renderer->searchAndRenderBlock($view, 'help');
}

protected function renderErrors(FormView $view)
{
return (string) $this->renderer->searchAndRenderBlock($view, 'errors');
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bridge/Twig/UndefinedCallableHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class UndefinedCallableHandler
'form_widget' => 'form',
'form_errors' => 'form',
'form_label' => 'form',
'form_help' => 'form',
'form_row' => 'form',
'form_rest' => 'form',
'form' => 'form',
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Twig/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"symfony/asset": "~3.4|~4.0",
"symfony/dependency-injection": "~3.4|~4.0",
"symfony/finder": "~3.4|~4.0",
"symfony/form": "^3.4.7|^4.0.7",
"symfony/form": "^4.1",
"symfony/http-foundation": "~3.4|~4.0",
"symfony/http-kernel": "~3.4|~4.0",
"symfony/polyfill-intl-icu": "~1.0",
Expand All @@ -41,7 +41,7 @@
"symfony/workflow": "~3.4|~4.0"
},
"conflict": {
"symfony/form": "<3.4.7|<4.0.7,>=4.0",
"symfony/form": "<4.1",
"symfony/console": "<3.4"
},
"suggest": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php if (!empty($help)): ?>
<p id=&quo 10000 t;<?php echo $view->escape($id); ?>_help" class="help-text"><?php echo $view->escape(false !== $translation_domain ? $view['translator']->trans($help, array(), $translation_domain) : $help); ?></p>
<?php endif; ?>
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<div>
<?php echo $view['form']->label($form) ?>
<?php echo $view['form']->errors($form) ?>
<?php echo $view['form']->widget($form) ?>
<?php $widgetAttr = empty($help) ? array() : array('attr' => array('aria-describedby' => $id.'_help')); ?>
<?php echo $view['form']->label($form); ?>
<?php echo $view['form']->errors($form); ?>
<?php echo $view['form']->widget($form, $widgetAttr); ?>
<?php echo $view['form']->help($form); ?>
</div>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
id="<?php echo $view->escape($id) ?>" name="<?php echo $view->escape($full_name) ?>"<?php if ($disabled): ?> disabled="disabled"<?php endif ?>
<?php if ($required): ?> required="required"<?php endif ?>
<?php echo $attr ? ' '.$view['form']->block($form, 'attributes') : '' ?>
<?php echo $attr ? ' '.$view['form']->block($form, 'attributes') : '' ?>
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<tr>
<?php $widgetAttr = empty($help) ? array() : array('attr' => array('aria-describedby' => $id.'_help')); ?>
<td>
<?php echo $view['form']->label($form); ?>
</td>
<td>
<?php echo $view['form']->errors($form); ?>
<?php echo $view['form']->widget($form); ?>
<?php echo $view['form']->widget($form, $widgetAttr); ?>
<?php echo $view['form']->help($form); ?>
</td>
</tr>
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,18 @@ public function label(FormView $view, $label = null, array $variables = array())
return $this->renderer->searchAndRenderBlock($view, 'label', $variables);
}

/**
* Renders the help of the given view.
*
* @param FormView $view The parent view
*
* @return string The HTML markup
*/
public function help(FormView $view): string
{
return $this->renderer->searchAndRenderBlock($view, 'help');
}

/**
* Renders the errors of the given view.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ protected function renderLabel(FormView $view, $label = null, array $vars = arra
return (string) $this->engine->get('form')->label($view, $label, $vars);
}

protected function renderHelp(FormView $view)
{
return (string) $this->engine->get('form')->help($view);
}

protected function renderErrors(FormView $view)
{
return (string) $this->engine->get('form')->errors($view);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ protected function renderLabel(FormView $view, $label = null, array $vars = arra
return (string) $this->engine->get('form')->label($view, $label, $vars);
}

protected function renderHelp(FormView $view)
{
return (string) $this->engine->get('form')->help($view);
}

protected function renderErrors(FormView $view)
{
return (string) $this->engine->get('form')->errors($view);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"symfony/dom-crawler": "~3.4|~4.0",
"symfony/polyfill-intl-icu": "~1.0",
"symfony/security": "~3.4|~4.0",
"symfony/form": "~3.4|~4.0",
"symfony/form": "^4.1",
"symfony/expression-language": "~3.4|~4.0",
"symfony/process": "~3.4|~4.0",
"symfony/security-core": "~3.4|~4.0",
Expand All @@ -65,7 +65,7 @@
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
"symfony/asset": "<3.4",
"symfony/console": "<3.4",
"symfony/form": "<3.4",
"symfony/form": "<4.1",
"symfony/property-info": "<3.4",
"symfony/serializer": "<4.1",
"symfony/stopwatch": "<3.4",
Expand Down
Loading
0