Merge branch '2.8' into 3.4
* 2.8: fixed deprecated messages in tests [HttpCache] Unlink tmp file on error Added LB translation for #26327 (Errors sign for people that do not see colors) [TwigBridge] Fix rendering of currency by MoneyType [HttpKernel] DumpDataCollector: do not flush when a dumper is provided
This commit is contained in:
commit
62eebd7d50
@ -96,6 +96,7 @@ class FormExtension extends AbstractExtension implements InitRuntimeInterface
|
||||
{
|
||||
return array(
|
||||
new TwigFilter('humanize', array('Symfony\Component\Form\FormRenderer', 'humanize')),
|
||||
new TwigFilter('form_encode_currency', array($this, 'encodeCurrency'), array('is_safe' => array('html'), 'needs_environment' => true)),
|
||||
);
|
||||
}
|
||||
|
||||
@ -166,6 +167,22 @@ class FormExtension extends AbstractExtension implements InitRuntimeInterface
|
||||
unset($this->$name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function encodeCurrency(Environment $environment, $text, $widget = '')
|
||||
{
|
||||
if ('UTF-8' === $charset = $environment->getCharset()) {
|
||||
$text = htmlspecialchars($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
|
||||
} else {
|
||||
$text = htmlentities($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
|
||||
$text = iconv('UTF-8', $charset, $text);
|
||||
$widget = iconv('UTF-8', $charset, $widget);
|
||||
}
|
||||
|
||||
return str_replace('{{ widget }}', $widget, $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -14,6 +14,83 @@
|
||||
{{- parent() -}}
|
||||
{%- endblock button_widget %}
|
||||
|
||||
{% block money_widget -%}
|
||||
{% set prepend = not (money_pattern starts with '{{') %}
|
||||
{% set append = not (money_pattern ends with '}}') %}
|
||||
{% if prepend or append %}
|
||||
<div class="input-group">
|
||||
{% if prepend %}
|
||||
<span class="input-group-addon">{{ money_pattern|form_encode_currency }}</span>
|
||||
{% endif %}
|
||||
{{- block('form_widget_simple') -}}
|
||||
{% if append %}
|
||||
<span class="input-group-addon">{{ money_pattern|form_encode_currency }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
{{- block('form_widget_simple') -}}
|
||||
{% endif %}
|
||||
{%- endblock money_widget %}
|
||||
|
||||
{% block percent_widget -%}
|
||||
<div class="input-group">
|
||||
{{- block('form_widget_simple') -}}
|
||||
<span class="input-group-addon">%</span>
|
||||
</div>
|
||||
{%- endblock percent_widget %}
|
||||
|
||||
{% block datetime_widget -%}
|
||||
{% if widget == 'single_text' %}
|
||||
{{- block('form_widget_simple') -}}
|
||||
{% else -%}
|
||||
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
|
||||
<div {{ block('widget_container_attributes') }}>
|
||||
{{- form_errors(form.date) -}}
|
||||
{{- form_errors(form.time) -}}
|
||||
{{- form_widget(form.date, { datetime: true } ) -}}
|
||||
{{- form_widget(form.time, { datetime: true } ) -}}
|
||||
</div>
|
||||
{%- endif %}
|
||||
{%- endblock datetime_widget %}
|
||||
|
||||
{% block date_widget -%}
|
||||
{% if widget == 'single_text' %}
|
||||
{{- block('form_widget_simple') -}}
|
||||
{% else -%}
|
||||
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
|
||||
{% if datetime is not defined or not datetime -%}
|
||||
<div {{ block('widget_container_attributes') -}}>
|
||||
{%- endif %}
|
||||
{{- date_pattern|replace({
|
||||
'{{ year }}': form_widget(form.year),
|
||||
'{{ month }}': form_widget(form.month),
|
||||
'{{ day }}': form_widget(form.day),
|
||||
})|raw -}}
|
||||
{% if datetime is not defined or not datetime -%}
|
||||
</div>
|
||||
{%- endif -%}
|
||||
{% endif %}
|
||||
{%- endblock date_widget %}
|
||||
|
||||
{% block time_widget -%}
|
||||
{% if widget == 'single_text' %}
|
||||
{{- block('form_widget_simple') -}}
|
||||
{% else -%}
|
||||
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-inline')|trim}) -%}
|
||||
{% if datetime is not defined or false == datetime -%}
|
||||
<div {{ block('widget_container_attributes') -}}>
|
||||
{%- endif -%}
|
||||
{{- form_widget(form.hour) }}{% if with_minutes %}:{{ form_widget(form.minute) }}{% endif %}{% if with_seconds %}:{{ form_widget(form.second) }}{% endif %}
|
||||
{% if datetime is not defined or false == datetime -%}
|
||||
</div>
|
||||
{%- endif -%}
|
||||
{% endif %}
|
||||
{%- endblock time_widget %}
|
||||
|
||||
{% block choice_widget_collapsed -%}
|
||||
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control')|trim}) %}
|
||||
{%- endblock choice_widget_collapsed %}
|
||||
|
||||
{% block checkbox_widget -%}
|
||||
{%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
|
||||
{% if 'checkbox-inline' in parent_label_class %}
|
||||
|
@ -177,7 +177,7 @@
|
||||
{%- endblock integer_widget -%}
|
||||
|
||||
{%- block money_widget -%}
|
||||
{{ money_pattern|replace({ '{{ widget }}': block('form_widget_simple') })|raw }}
|
||||
{{ money_pattern|form_encode_currency(block('form_widget_simple')) }}
|
||||
{%- endblock money_widget -%}
|
||||
|
||||
{%- block url_widget -%}
|
||||
|
@ -75,6 +75,31 @@ class FormExtensionBootstrap3LayoutTest extends AbstractBootstrap3LayoutTest
|
||||
$this->assertSame('<form name="form" method="get" action="0">', $html);
|
||||
}
|
||||
|
||||
public function testMoneyWidgetInIso()
|
||||
{
|
||||
$environment = new Environment(new StubFilesystemLoader(array(
|
||||
__DIR__.'/../../Resources/views/Form',
|
||||
__DIR__.'/Fixtures/templates/form',
|
||||
)), array('strict_variables' => true));
|
||||
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
||||
$environment->addExtension($this->extension);
|
||||
$environment->setCharset('ISO-8859-1');
|
||||
|
||||
$this->extension->initRuntime($environment);
|
||||
|
||||
$view = $this->factory
|
||||
->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\MoneyType')
|
||||
->createView()
|
||||
;
|
||||
|
||||
$this->assertSame(<<<'HTML'
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">€ </span>
|
||||
<input type="text" id="name" name="name" required="required" class="form-control" /> </div>
|
||||
HTML
|
||||
, trim($this->renderWidget($view)));
|
||||
}
|
||||
|
||||
protected function renderForm(FormView $view, array $vars = array())
|
||||
{
|
||||
return (string) $this->renderer->renderBlock($view, 'form', $vars);
|
||||
|
@ -165,6 +165,26 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
|
||||
$this->assertSame($expected, \Symfony\Bridge\Twig\Extension\twig_is_root_form($formView));
|
||||
}
|
||||
|
||||
public function testMoneyWidgetInIso()
|
||||
{
|
||||
$environment = new Environment(new StubFilesystemLoader(array(
|
||||
__DIR__.'/../../Resources/views/Form',
|
||||
__DIR__.'/Fixtures/templates/form',
|
||||
)), array('strict_variables' => true));
|
||||
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
||||
$environment->addExtension($this->extension);
|
||||
$environment->setCharset('ISO-8859-1');
|
||||
|
||||
$this->extension->initRuntime($environment);
|
||||
|
||||
$view = $this->factory
|
||||
->createNamed('name', 'money')
|
||||
->createView()
|
||||
;
|
||||
|
||||
$this->assertSame('€ <input type="text" id="name" name="name" required="required" />', $this->renderWidget($view));
|
||||
}
|
||||
|
||||
protected function renderForm(FormView $view, array $vars = array())
|
||||
{
|
||||
return (string) $this->renderer->renderBlock($view, 'form', $vars);
|
||||
|
@ -1 +1 @@
|
||||
<?php echo str_replace('{{ widget }}', $view['form']->block($form, 'form_widget_simple'), $money_pattern) ?>
|
||||
<?php echo $view['form']->formEncodeCurrency($money_pattern, $view['form']->block($form, 'form_widget_simple')) ?>
|
||||
|
@ -240,4 +240,20 @@ class FormHelper extends Helper
|
||||
{
|
||||
return $this->renderer->humanize($text);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function formEncodeCurrency($text, $widget = '')
|
||||
{
|
||||
if ('UTF-8' === $charset = $this->getCharset()) {
|
||||
$text = htmlspecialchars($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
|
||||
} else {
|
||||
$text = htmlentities($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
|
||||
$text = iconv('UTF-8', $charset, $text);
|
||||
$widget = iconv('UTF-8', $charset, $widget);
|
||||
}
|
||||
|
||||
return str_replace('{{ widget }}', $widget, $text);
|
||||
}
|
||||
}
|
||||
|
@ -81,6 +81,18 @@ class FormHelperDivLayoutTest extends AbstractDivLayoutTest
|
||||
$this->assertSame('<form name="form" method="get" action="0">', $html);
|
||||
}
|
||||
|
||||
public function testMoneyWidgetInIso()
|
||||
{
|
||||
$this->engine->setCharset('ISO-8859-1');
|
||||
|
||||
$view = $this->factory
|
||||
->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\MoneyType')
|
||||
->createView()
|
||||
;
|
||||
|
||||
$this->assertSame('€ <input type="text" id="name" name="name" required="required" />', $this->renderWidget($view));
|
||||
}
|
||||
|
||||
protected function renderForm(FormView $view, array $vars = array())
|
||||
{
|
||||
return (string) $this->engine->get('form')->form($view, $vars);
|
||||
|
@ -70,7 +70,7 @@ class MoneyType extends AbstractType
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pattern for this locale.
|
||||
* Returns the pattern for this locale in UTF-8.
|
||||
*
|
||||
* The pattern contains the placeholder "{{ widget }}" where the HTML tag should
|
||||
* be inserted
|
||||
|
@ -67,7 +67,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
||||
if ($this->stopwatch) {
|
||||
$this->stopwatch->start('dump');
|
||||
}
|
||||
if ($this->isCollected) {
|
||||
if ($this->isCollected && !$this->dumper) {
|
||||
$this->isCollected = false;
|
||||
}
|
||||
|
||||
|
@ -387,16 +387,22 @@ class Store implements StoreInterface
|
||||
|
||||
$tmpFile = tempnam(dirname($path), basename($path));
|
||||
if (false === $fp = @fopen($tmpFile, 'wb')) {
|
||||
@unlink($tmpFile);
|
||||
|
||||
return false;
|
||||
}
|
||||
@fwrite($fp, $data);
|
||||
@fclose($fp);
|
||||
|
||||
if ($data != file_get_contents($tmpFile)) {
|
||||
@unlink($tmpFile);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (false === @rename($tmpFile, $path)) {
|
||||
@unlink($tmpFile);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\VarDumper\Cloner\Data;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
@ -112,4 +113,24 @@ EOTXT;
|
||||
$collector->__destruct();
|
||||
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean());
|
||||
}
|
||||
|
||||
public function testFlushNothingWhenDataDumperIsProvided()
|
||||
{
|
||||
$data = new Data(array(array(456)));
|
||||
$dumper = new CliDumper('php://output');
|
||||
$collector = new DumpDataCollector(null, null, null, null, $dumper);
|
||||
|
||||
ob_start();
|
||||
$collector->dump($data);
|
||||
$line = __LINE__ - 1;
|
||||
if (\PHP_VERSION_ID >= 50400) {
|
||||
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean());
|
||||
} else {
|
||||
$this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", ob_get_clean());
|
||||
}
|
||||
|
||||
ob_start();
|
||||
$collector->__destruct();
|
||||
$this->assertEmpty(ob_get_clean());
|
||||
}
|
||||
}
|
||||
|
@ -314,6 +314,10 @@
|
||||
<source>This is not a valid Business Identifier Code (BIC).</source>
|
||||
<target>Dëst ass kee gëltege "Business Identifier Code" (BIC).</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="82">
|
||||
<source>Error</source>
|
||||
<target>Feeler</target>
|
||||
</trans-unit>
|
||||
</body>
|
||||
</file>
|
||||
</xliff>
|
||||
|
Reference in New Issue
Block a user