Skip to content

Commit 48df9ae

Browse files
Merge branch '5.0'
* 5.0: (36 commits) Add test for tagged iterator with numeric index Fix container lint command when a synthetic service is used in combination with the expression language Fix Travis script [Validator][Range] Fix typos [SecurityBundle] Minor fix in LDAP config tree builder [HttpClient] fix requests to hosts that idn_to_ascii() cannot handle Revert "minor #35559 [FrameworkBundle] remove mention of the old Controller class (nicolas-grekas)" [FrameworkBundle] remove redundant PHPDoc in console Descriptor and subclass [Mime] remove phpdoc mentioning Utf8AddressEncoder Add missing phpdoc Remove int return type from FlattenException::getCode [Yaml] fix dumping strings containing CRs [DI] Fix XmlFileLoader bad error message [Form] Handle false as empty value on expanded choices [Messenger] Add ext-redis min version req to tests Tweak message improve PlaintextPasswordEncoder docBlock summary [Validator] Add two missing translations for the Arabic (ar) locale Use some PHP 5.4 constants unconditionally Add new packages on the link script ...
2 parents a076cef + 93add72 commit 48df9ae

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

Extension/Core/Type/CheckboxType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
3333
// doing so also calls setDataLocked(true).
3434
$builder->setData(isset($options['data']) ? $options['data'] : false);
3535
$builder->addViewTransformer(new BooleanToStringTransformer($options['value'], $options['false_values']));
36+
$builder->setAttribute('_false_is_empty', true); // @internal - A boolean flag to treat false as empty, see Form::isEmpty() - Do not rely on it, it will be removed in Symfony 5.1.
3637
}
3738

3839
/**

Form.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,9 @@ public function isEmpty()
742742
// arrays, countables
743743
((\is_array($this->modelData) || $this->modelData instanceof \Countable) && 0 === \count($this->modelData)) ||
744744
// traversables that are not countable
745-
($this->modelData instanceof \Traversable && 0 === iterator_count($this->modelData));
745+
($this->modelData instanceof \Traversable && 0 === iterator_count($this->modelData)) ||
746+
// @internal - Do not rely on it, it will be removed in Symfony 5.1.
747+
(false === $this->modelData && $this->config->getAttribute('_false_is_empty'));
746748
}
747749

748750
/**

FormRenderer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ public function humanize(string $text)
291291
public function encodeCurrency(Environment $environment, string $text, string $widget = ''): string
292292
{
293293
if ('UTF-8' === $charset = $environment->getCharset()) {
294-
$text = htmlspecialchars($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
294+
$text = htmlspecialchars($text, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
295295
} else {
296-
$text = htmlentities($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
296+
$text = htmlentities($text, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
297297
$text = iconv('UTF-8', $charset, $text);
298298
$widget = iconv('UTF-8', $charset, $widget);
299299
}

Tests/Extension/Core/Type/CheckboxTypeTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,13 @@ public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expect
220220
$this->assertSame($expectedData, $form->getNormData());
221221
$this->assertSame($expectedData, $form->getData());
222222
}
223+
224+
public function testSubmitNullIsEmpty()
225+
{
226+
$form = $this->factory->create(static::TESTED_TYPE);
227+
228+
$form->submit(null);
229+
230+
$this->assertTrue($form->isEmpty());
231+
}
223232
}

Tests/Extension/Core/Type/ChoiceTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,7 @@ public function provideTrimCases()
20532053
/**
20542054
* @dataProvider expandedIsEmptyWhenNoRealChoiceIsSelectedProvider
20552055
*/
2056-
public function testExpandedIsEmptyWhenNoRealChoiceIsSelected(bool $expected, $submittedData, bool $multiple, bool $required, $placeholder)
2056+
public function testExpandedIsEmptyWhenNoRealChoiceIsSelected($expected, $submittedData, $multiple, $required, $placeholder)
20572057
{
20582058
$options = [
20592059
'expanded' => true,

0 commit comments

Comments
 (0)