[Form] [TwigBridge] Bootstrap layout whitespace control
This commit is contained in:
parent
2559628654
commit
e8b06787b0
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
{% block form_widget_simple -%}
|
{% block form_widget_simple -%}
|
||||||
{% if type is not defined or 'file' != type %}
|
{% if type is not defined or 'file' != type %}
|
||||||
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control')|trim}) %}
|
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-control')|trim}) -%}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{- parent() -}}
|
{{- parent() -}}
|
||||||
{%- endblock form_widget_simple %}
|
{%- endblock form_widget_simple %}
|
||||||
@ -42,48 +42,48 @@
|
|||||||
{% block datetime_widget -%}
|
{% block datetime_widget -%}
|
||||||
{% if widget == 'single_text' %}
|
{% if widget == 'single_text' %}
|
||||||
{{- block('form_widget_simple') -}}
|
{{- block('form_widget_simple') -}}
|
||||||
{% else %}
|
{% else -%}
|
||||||
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) %}
|
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
|
||||||
<div {{ block('widget_container_attributes') }}>
|
<div {{ block('widget_container_attributes') }}>
|
||||||
{{ form_errors(form.date) }}
|
{{- form_errors(form.date) -}}
|
||||||
{{ form_errors(form.time) }}
|
{{- form_errors(form.time) -}}
|
||||||
{{ form_widget(form.date, { datetime: true } ) }}
|
{{- form_widget(form.date, { datetime: true } ) -}}
|
||||||
{{ form_widget(form.time, { datetime: true } ) }}
|
{{- form_widget(form.time, { datetime: true } ) -}}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{%- endif %}
|
||||||
{%- endblock datetime_widget %}
|
{%- endblock datetime_widget %}
|
||||||
|
|
||||||
{% block date_widget -%}
|
{% block date_widget -%}
|
||||||
{% if widget == 'single_text' %}
|
{% if widget == 'single_text' %}
|
||||||
{{- block('form_widget_simple') -}}
|
{{- block('form_widget_simple') -}}
|
||||||
{% else %}
|
{% else -%}
|
||||||
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) %}
|
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
|
||||||
{% if datetime is not defined or not datetime %}
|
{% if datetime is not defined or not datetime -%}
|
||||||
<div {{ block('widget_container_attributes') -}}>
|
<div {{ block('widget_container_attributes') -}}>
|
||||||
{% endif %}
|
{%- endif %}
|
||||||
{{ date_pattern|replace({
|
{{- date_pattern|replace({
|
||||||
'{{ year }}': form_widget(form.year),
|
'{{ year }}': form_widget(form.year),
|
||||||
'{{ month }}': form_widget(form.month),
|
'{{ month }}': form_widget(form.month),
|
||||||
'{{ day }}': form_widget(form.day),
|
'{{ day }}': form_widget(form.day),
|
||||||
})|raw }}
|
})|raw -}}
|
||||||
{% if datetime is not defined or not datetime %}
|
{% if datetime is not defined or not datetime -%}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{%- endif -%}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{%- endblock date_widget %}
|
{%- endblock date_widget %}
|
||||||
|
|
||||||
{% block time_widget -%}
|
{% block time_widget -%}
|
||||||
{% if widget == 'single_text' %}
|
{% if widget == 'single_text' %}
|
||||||
{{- block('form_widget_simple') -}}
|
{{- block('form_widget_simple') -}}
|
||||||
{% else %}
|
{% else -%}
|
||||||
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) %}
|
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
|
||||||
{% if datetime is not defined or false == datetime %}
|
{% if datetime is not defined or false == datetime -%}
|
||||||
<div {{ block('widget_container_attributes') -}}>
|
<div {{ block('widget_container_attributes') -}}>
|
||||||
{% endif %}
|
{%- endif -%}
|
||||||
{{ form_widget(form.hour) }}:{{ form_widget(form.minute) }}{% if with_seconds %}:{{ form_widget(form.second) }}{% endif %}
|
{{- form_widget(form.hour) }}:{{ form_widget(form.minute) }}{% if with_seconds %}:{{ form_widget(form.second) }}{% endif %}
|
||||||
{% if datetime is not defined or false == datetime %}
|
{% if datetime is not defined or false == datetime -%}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{%- endif -%}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{%- endblock time_widget %}
|
{%- endblock time_widget %}
|
||||||
|
|
||||||
@ -93,57 +93,57 @@
|
|||||||
{%- endblock %}
|
{%- endblock %}
|
||||||
|
|
||||||
{% block choice_widget_expanded -%}
|
{% block choice_widget_expanded -%}
|
||||||
{% if '-inline' in label_attr.class|default('') %}
|
{% if '-inline' in label_attr.class|default('') -%}
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
{% for child in form %}
|
{%- for child in form %}
|
||||||
{{ form_widget(child, {
|
{{- form_widget(child, {
|
||||||
parent_label_class: label_attr.class|default(''),
|
parent_label_class: label_attr.class|default(''),
|
||||||
}) }}
|
}) -}}
|
||||||
{% endfor %}
|
{% endfor -%}
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{%- else -%}
|
||||||
<div {{ block('widget_container_attributes') }}>
|
<div {{ block('widget_container_attributes') }}>
|
||||||
{% for child in form %}
|
{%- for child in form %}
|
||||||
{{ form_widget(child, {
|
{{- form_widget(child, {
|
||||||
parent_label_class: label_attr.class|default(''),
|
parent_label_class: label_attr.class|default(''),
|
||||||
}) }}
|
}) -}}
|
||||||
{% endfor %}
|
{% endfor -%}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{%- endif %}
|
||||||
{%- endblock choice_widget_expanded %}
|
{%- endblock choice_widget_expanded %}
|
||||||
|
|
||||||
{% block checkbox_widget -%}
|
{% block checkbox_widget -%}
|
||||||
{% set parent_label_class = parent_label_class|default('') %}
|
{% set parent_label_class = parent_label_class|default('') -%}
|
||||||
{% if 'checkbox-inline' in parent_label_class %}
|
{% if 'checkbox-inline' in parent_label_class %}
|
||||||
{{ form_label(form, null, { widget: parent() }) }}
|
{{- form_label(form, null, { widget: parent() }) -}}
|
||||||
{% else %}
|
{% else -%}
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
{{ form_label(form, null, { widget: parent() }) }}
|
{{- form_label(form, null, { widget: parent() }) -}}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{%- endif %}
|
||||||
{%- endblock checkbox_widget %}
|
{%- endblock checkbox_widget %}
|
||||||
|
|
||||||
{% block radio_widget -%}
|
{% block radio_widget -%}
|
||||||
{% set parent_label_class = parent_label_class|default('') %}
|
{%- set parent_label_class = parent_label_class|default('') -%}
|
||||||
{% if 'radio-inline' in parent_label_class %}
|
{% if 'radio-inline' in parent_label_class %}
|
||||||
{{ form_label(form, null, { widget: parent() }) }}
|
{{- form_label(form, null, { widget: parent() }) -}}
|
||||||
{% else %}
|
{% else -%}
|
||||||
<div class="radio">
|
<div class="radio">
|
||||||
{{ form_label(form, null, { widget: parent() }) }}
|
{{- form_label(form, null, { widget: parent() }) -}}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{%- endif %}
|
||||||
{%- endblock radio_widget %}
|
{%- endblock radio_widget %}
|
||||||
|
|
||||||
{# Labels #}
|
{# Labels #}
|
||||||
|
|
||||||
{% block form_label -%}
|
{% block form_label -%}
|
||||||
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' control-label')|trim}) %}
|
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' control-label')|trim}) -%}
|
||||||
{{- parent() -}}
|
{{- parent() -}}
|
||||||
{%- endblock form_label %}
|
{%- endblock form_label %}
|
||||||
|
|
||||||
{% block choice_label %}
|
{% block choice_label -%}
|
||||||
{# remove the checkbox-inline and radio-inline class, it's only useful for embed labels #}
|
{# remove the checkbox-inline and radio-inline class, it's only useful for embed labels #}
|
||||||
{% set label_attr = label_attr|merge({class: label_attr.class|default('')|replace({'checkbox-inline': '', 'radio-inline': ''})|trim}) %}
|
{%- set label_attr = label_attr|merge({class: label_attr.class|default('')|replace({'checkbox-inline': '', 'radio-inline': ''})|trim}) -%}
|
||||||
{{- block('form_label') -}}
|
{{- block('form_label') -}}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
@ -168,8 +168,8 @@
|
|||||||
{% set label = name|humanize %}
|
{% set label = name|humanize %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
|
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
|
||||||
{{ widget|raw }}
|
{{- widget|raw -}}
|
||||||
{{ label is not sameas(false) ? label|trans({}, translation_domain) }}
|
{{- label is not sameas(false) ? label|trans({}, translation_domain) -}}
|
||||||
</label>
|
</label>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock checkbox_radio_label %}
|
{% endblock checkbox_radio_label %}
|
||||||
@ -178,9 +178,9 @@
|
|||||||
|
|
||||||
{% block form_row -%}
|
{% block form_row -%}
|
||||||
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
|
<div class="form-group{% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
|
||||||
{{ form_label(form) }}
|
{{- form_label(form) -}}
|
||||||
{{ form_widget(form) }}
|
{{- form_widget(form) -}}
|
||||||
{{ form_errors(form) }}
|
{{- form_errors(form) -}}
|
||||||
</div>
|
</div>
|
||||||
{%- endblock form_row %}
|
{%- endblock form_row %}
|
||||||
|
|
||||||
@ -192,35 +192,35 @@
|
|||||||
|
|
||||||
{% block choice_row -%}
|
{% block choice_row -%}
|
||||||
{% set force_error = true %}
|
{% set force_error = true %}
|
||||||
{{ block('form_row') }}
|
{{- block('form_row') }}
|
||||||
{%- endblock choice_row %}
|
{%- endblock choice_row %}
|
||||||
|
|
||||||
{% block date_row -%}
|
{% block date_row -%}
|
||||||
{% set force_error = true %}
|
{% set force_error = true %}
|
||||||
{{ block('form_row') }}
|
{{- block('form_row') }}
|
||||||
{%- endblock date_row %}
|
{%- endblock date_row %}
|
||||||
|
|
||||||
{% block time_row -%}
|
{% block time_row -%}
|
||||||
{% set force_error = true %}
|
{% set force_error = true %}
|
||||||
{{ block('form_row') }}
|
{{- block('form_row') }}
|
||||||
{%- endblock time_row %}
|
{%- endblock time_row %}
|
||||||
|
|
||||||
{% block datetime_row -%}
|
{% block datetime_row -%}
|
||||||
{% set force_error = true %}
|
{% set force_error = true %}
|
||||||
{{ block('form_row') }}
|
{{- block('form_row') }}
|
||||||
{%- endblock datetime_row %}
|
{%- endblock datetime_row %}
|
||||||
|
|
||||||
{% block checkbox_row -%}
|
{% block checkbox_row -%}
|
||||||
<div class="form-group{% if not valid %} has-error{% endif %}">
|
<div class="form-group{% if not valid %} has-error{% endif %}">
|
||||||
{{ form_widget(form) }}
|
{{- form_widget(form) -}}
|
||||||
{{ form_errors(form) }}
|
{{- form_errors(form) -}}
|
||||||
</div>
|
</div>
|
||||||
{%- endblock checkbox_row %}
|
{%- endblock checkbox_row %}
|
||||||
|
|
||||||
{% block radio_row -%}
|
{% block radio_row -%}
|
||||||
<div class="form-group{% if not valid %} has-error{% endif %}">
|
<div class="form-group{% if not valid %} has-error{% endif %}">
|
||||||
{{ form_widget(form) }}
|
{{- form_widget(form) -}}
|
||||||
{{ form_errors(form) }}
|
{{- form_errors(form) -}}
|
||||||
</div>
|
</div>
|
||||||
{%- endblock radio_row %}
|
{%- endblock radio_row %}
|
||||||
|
|
||||||
@ -231,7 +231,7 @@
|
|||||||
{% if form.parent %}<span class="help-block">{% else %}<div class="alert alert-danger">{% endif %}
|
{% if form.parent %}<span class="help-block">{% else %}<div class="alert alert-danger">{% endif %}
|
||||||
<ul class="list-unstyled">
|
<ul class="list-unstyled">
|
||||||
{%- for error in errors -%}
|
{%- for error in errors -%}
|
||||||
<li><span class="glyphicon glyphicon-exclamation-sign"></span> {{ error.message }}</li>
|
<li><span class="glyphicon glyphicon-exclamation-sign"></span>{{ error.message }}</li>
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
</ul>
|
</ul>
|
||||||
{% if form.parent %}</span>{% else %}</div>{% endif %}
|
{% if form.parent %}</span>{% else %}</div>{% endif %}
|
||||||
|
@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\Twig\Tests\Extension;
|
||||||
|
|
||||||
|
use Symfony\Bridge\Twig\Extension\FormExtension;
|
||||||
|
use Symfony\Bridge\Twig\Form\TwigRenderer;
|
||||||
|
use Symfony\Bridge\Twig\Form\TwigRendererEngine;
|
||||||
|
use Symfony\Bridge\Twig\Extension\TranslationExtension;
|
||||||
|
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
|
||||||
|
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
|
||||||
|
use Symfony\Component\Form\FormView;
|
||||||
|
use Symfony\Component\Form\Tests\AbstractBootstrap3LayoutTest;
|
||||||
|
|
||||||
|
class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var FormExtension
|
||||||
|
*/
|
||||||
|
protected $extension;
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$rendererEngine = new TwigRendererEngine(array(
|
||||||
|
'bootstrap_3_layout.html.twig',
|
||||||
|
'custom_widgets.html.twig',
|
||||||
|
));
|
||||||
|
$renderer = new TwigRenderer($rendererEngine, $this->getMock('Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface'));
|
||||||
|
|
||||||
|
$this->extension = new FormExtension($renderer);
|
||||||
|
|
||||||
|
$loader = new StubFilesystemLoader(array(
|
||||||
|
__DIR__.'/../../Resources/views/Form',
|
||||||
|
__DIR__.'/Fixtures/templates/form',
|
||||||
|
));
|
||||||
|
|
||||||
|
$environment = new \Twig_Environment($loader, array('strict_variables' => true));
|
||||||
|
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
||||||
|
$environment->addExtension($this->extension);
|
||||||
|
|
||||||
|
$this->extension->initRuntime($environment);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown()
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
$this->extension = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderForm(FormView $view, array $vars = array())
|
||||||
|
{
|
||||||
|
return (string) $this->extension->renderer->renderBlock($view, 'form', $vars);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderEnctype(FormView $view)
|
||||||
|
{
|
||||||
|
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'enctype');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderLabel(FormView $view, $label = null, array $vars = array())
|
||||||
|
{
|
||||||
|
if ($label !== null) {
|
||||||
|
$vars += array('label' => $label);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'label', $vars);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderErrors(FormView $view)
|
||||||
|
{
|
||||||
|
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'errors');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderWidget(FormView $view, array $vars = array())
|
||||||
|
{
|
||||||
|
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'widget', $vars);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderRow(FormView $view, array $vars = array())
|
||||||
|
{
|
||||||
|
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'row', $vars);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderRest(FormView $view, array $vars = array())
|
||||||
|
{
|
||||||
|
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'rest', $vars);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderStart(FormView $view, array $vars = array())
|
||||||
|
{
|
||||||
|
return (string) $this->extension->renderer->renderBlock($view, 'form_start', $vars);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderEnd(FormView $view, array $vars = array())
|
||||||
|
{
|
||||||
|
return (string) $this->extension->renderer->renderBlock($view, 'form_end', $vars);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setTheme(FormView $view, array $themes)
|
||||||
|
{
|
||||||
|
$this->extension->renderer->setTheme($view, $themes);
|
||||||
|
}
|
||||||
|
}
|
1818
src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php
Normal file
1818
src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php
Normal file
File diff suppressed because it is too large
Load Diff
@ -92,9 +92,15 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
|||||||
'attr' => array('class' => 'my&class'),
|
'attr' => array('class' => 'my&class'),
|
||||||
), $vars));
|
), $vars));
|
||||||
|
|
||||||
$xpath = trim($xpath).'
|
if (!isset($vars['id'])) {
|
||||||
[@id="my&id"]
|
$xpath = trim($xpath).'
|
||||||
|
[@id="my&id"]';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($vars['attr']['class'])) {
|
||||||
|
$xpath .= '
|
||||||
[@class="my&class"]';
|
[@class="my&class"]';
|
||||||
|
}
|
||||||
|
|
||||||
$this->assertMatchesXpath($html, $xpath);
|
$this->assertMatchesXpath($html, $xpath);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user