Skip to content

[Form] Deprecate calling FormErrorIterator::children() if the current element is not iterable #42387

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
Show file tree
Hide file tree
Changes from all commits
Commits
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
* Deprecated calling FormErrorIterator::children() if the current e…
…lement is not iterable
  • Loading branch information
W0rma committed Aug 5, 2021
commit d8e74fc8df18ee02fe24e31ea7a1b46be0ee669c
5 changes: 5 additions & 0 deletions UPGRADE-5.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------

Expand Down
1 change: 1 addition & 0 deletions UPGRADE-6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/Symfony/Component/Form/FormErrorIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down