[Form] Fix "Array was modified outside object" in ResizeFormListener.

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #10405
| License       | MIT
| Doc PR        |

This is the second pull request for this issue. The history of this is as follows:

Original Fix was added Feb 11th under Pull Request #10232.
Users began complaining of Doctrine ArrayCollection not being updated in forms.
Revert was added Feb 15th under Pull Request #10269.
Issue #10405 was opened on 7th Mar for the original bug.

Pull Request #10269 has a failing test that illustrates users concerns.
I have added failing tests to this pull request to illustrate the problems described in #10405.

The tests will now pass, but I'm not really happy with what needed to be done to accomplish it.

The difficulty is in determining if the IteratorAggregate $data is backed by an array or an object. Given the abstract nature of how ResizeFormListener::onSubmit works with collections, I cannot make any assumptions as to what $data is.

To compound the problem, not only can I not make assumptions, I also cannot directly observe the contents of $data. The only way I can determine what is backing $data is by trying to modify it via an Iterator: If calling unset on the iterator affects $data, I know I have an array, otherwise I have an object.

Since I can only determine what I am working with after I modify it, then I have to do the rather inefficient thing of using the Iterator first, then checking the iterators contents agains $data, and if they don't match, falling back to the foreach method of direct manipulation.

I really cannot think of any better way to resolve this bug. I'd love some suggestions.