From d8e74fc8df18ee02fe24e31ea7a1b46be0ee669c Mon Sep 17 00:00:00 2001 From: W0rma Date: Thu, 5 Aug 2021 09:42:24 +0200 Subject: [PATCH] * Deprecated calling `FormErrorIterator::children()` if the current element is not iterable --- UPGRADE-5.4.md | 5 +++++ UPGRADE-6.0.md | 1 + src/Symfony/Component/Form/CHANGELOG.md | 1 + src/Symfony/Component/Form/FormErrorIterator.php | 8 ++++++-- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/UPGRADE-5.4.md b/UPGRADE-5.4.md index 54f41b746e496..006a21ccbcc5d 100644 --- a/UPGRADE-5.4.md +++ b/UPGRADE-5.4.md @@ -12,6 +12,11 @@ Finder * Deprecate `Comparator::setTarget()` and `Comparator::setOperator()` * Add a constructor to `Comparator` that allows setting target and operator +Form +------ + + * Deprecate calling `FormErrorIterator::children()` if the current element is not iterable. + FrameworkBundle --------------- diff --git a/UPGRADE-6.0.md b/UPGRADE-6.0.md index 57f1e455fe0a7..4ed6cf78d7226 100644 --- a/UPGRADE-6.0.md +++ b/UPGRADE-6.0.md @@ -69,6 +69,7 @@ Finder Form ---- + * `FormErrorIterator::children()` throws an exception if the current element is not iterable. * The default value of the `rounding_mode` option of the `PercentType` has been changed to `\NumberFormatter::ROUND_HALFUP`. * The default rounding mode of the `PercentToLocalizedStringTransformer` has been changed to `\NumberFormatter::ROUND_HALFUP`. * Added the `getIsEmptyCallback()` method to the `FormConfigInterface`. diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index ddc90bc68f9b6..5244548952d5d 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 5.4 --- + * Deprecate calling `FormErrorIterator::children()` if the current element is not iterable. * Allow to pass `TranslatableMessage` objects to the `help` option 5.3 diff --git a/src/Symfony/Component/Form/FormErrorIterator.php b/src/Symfony/Component/Form/FormErrorIterator.php index f339e8621b7bd..6a9ebb9ba3635 100644 --- a/src/Symfony/Component/Form/FormErrorIterator.php +++ b/src/Symfony/Component/Form/FormErrorIterator.php @@ -13,6 +13,7 @@ use Symfony\Component\Form\Exception\BadMethodCallException; use Symfony\Component\Form\Exception\InvalidArgumentException; +use Symfony\Component\Form\Exception\LogicException; use Symfony\Component\Form\Exception\OutOfBoundsException; use Symfony\Component\Validator\ConstraintViolation; @@ -213,13 +214,16 @@ public function hasChildren() } /** - * Alias of {@link current()}. - * * @return self */ #[\ReturnTypeWillChange] public function getChildren() { + if (!$this->hasChildren()) { + trigger_deprecation('symfony/form', '5.4', 'Calling "%s()" if the current element is not iterable is deprecated, call "%s" to get the current element.', __METHOD__, self::class.'::current()'); + // throw new LogicException(sprintf('The current element is not iterable. Use "%s" to get the current element.', self::class.'::current()')); + } + return current($this->errors); }