Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Fix for the implementation of Collection Element #5636

Closed
wants to merge 20 commits into from
Closed

Fix for the implementation of Collection Element #5636

wants to merge 20 commits into from

Conversation

stldo
Copy link

@stldo stldo commented Dec 21, 2013

The current implementation of Collection Element imposes, in prepareFieldset(), that the child element keys are set sequentially, starting from "0". After that, populateValues() will remove the unused indexes and add new ones, according to the input data. This behaviour breaks the test in this commit, as it expects that the first key will always be "0", which is not always true (as when collection elements are dinamically added or removed with javascript). The changes done here makes Collection Element more flexible and maybe a little faster, as it saves resources by avoiding unnecessary creation of child elements, adding them just when neccessary. Also, self::$lastChildIndex can be sent along with the template, so javascript can set a proper index for the next element to be added. FieldsetPrepareAwareInterface and all its references were removed, as they are no longer necessary.

The current implementation of Collection Element imposes, in
prepareFieldset(), that the child element keys are set sequentially,
starting from 0. After that, populateValues() will remove the unused
indexes and add new ones, according to the input data. This behaviour
breaks the test in this commit, as it expects that the first key will
always be '0', which is not always true, as when collection elements
are dinamically added or removed with javascript. The changes done here
makes Collection Element more flexible and maybe a little faster, as it
saves resources by avoiding unnecessary creation of child elements,
adding them just when neccessary. Also, self::$lastChildIndex can be
sent along with the template, so javascript can set a proper index for
the next element to be added. FieldsetPrepareAwareInterface and all its
references were removed, as they are no longer necessary.
@stldo
Copy link
Author

stldo commented Dec 21, 2013

Also it seems to solve issues #4094, #4492 and #5010.

use Zend\Form\FormInterface;
use Zend\Stdlib\ArrayUtils;

class Collection extends Fieldset implements FieldsetPrepareAwareInterface
class Collection extends Fieldset
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you removing the FieldsetPrepareAwareInterface implementation? or is this due to submitting from an out-of-date master branch?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the Collection class implements FieldsetPrepareAwareInterface, it's being used in L183 in the Fieldset class just to call prepareFieldset(). The changes done makes FieldsetPrepareAwareInterface useless, as prepareFieldset() isn't needed anymore.

@weierophinney
Copy link
Member

@saltoledo Please rebase your branch from current master, resolve the conflicts, and do a force push. Currently, it looks like this is based on a very out-of-date version, and I'm worried that the changes introduced either overwrite or break new functionality.

@stefanotorresi
Copy link
Contributor

#4492 is not resolved by this PR

@weierophinney
Copy link
Member

@saltoledo Notice that GitHub is reporting that the PR cannot be automatically merged -- this is an indication that the code you've written is out-of-date with current master.

In your branch, do the following; assume that origin is pointing to this repository, and saltoledo is pointing to your own -- and change the commands accordingly if those are not the names of your remotes.

git fetch origin
git rebase origin/master
git push -f saltoledo form-collection-fix:form-collection-fix

You'll likely find that when you do the rebase that you have merge conflicts. use git mergetool to resolve those. Only run the last command after the rebase issues are resolved.

@ins0
Copy link
Contributor

ins0 commented Feb 3, 2014

@saltoledo are u work on this fix anymore?
@weierophinney merged his changes in my local branch and rebased origin/master and found no conflicts and tests running green - should i create a pull request when @saltoledo is currently bussy? i think this is a really ugly bug and needs to resolved

@stldo
Copy link
Author

stldo commented Feb 14, 2014

Sorry, I was under a health treatment and unable to work. @weierophinney, when I execute 'git rebase origin/master', it returns 'Current branch form-collection-fix is up to date.'

saltoledo added 12 commits February 14, 2014 00:12
This rolls back to commit 99d16a4.
This rolls back to commit 43a65f7.
The current implementation of Collection Element imposes, in
prepareFieldset(), that the child element keys are set sequentially,
starting from 0. After that, populateValues() will remove the unused
indexes and add new ones, according to the input data. This behaviour
breaks the test in this commit, as it expects that the first key will
always be '0', which is not always true, as when collection elements
are dinamically added or removed with javascript. The changes done here
makes Collection Element more flexible and maybe a little faster, as it
saves resources by avoiding unnecessary creation of child elements,
adding them just when neccessary. Also, self::$lastChildIndex can be
sent along with the template, so javascript can set a proper index for
the next element to be added. FieldsetPrepareAwareInterface and all its
references were removed, as they are no longer necessary.
…ild elements if they all were removed"

This reverts commit 99d16a4.
This rolls back to commit 99d16a4.
This rolls back to commit 43a65f7.
@stldo
Copy link
Author

stldo commented Feb 14, 2014

@weierophinney I think everything is all right now. I'm still a little rusty, sorry for the mess.

@ins0
Copy link
Contributor

ins0 commented Feb 14, 2014

👍

@weierophinney weierophinney added this to the 2.2.6 milestone Mar 3, 2014
@weierophinney weierophinney self-assigned this Mar 3, 2014
weierophinney added a commit that referenced this pull request Mar 3, 2014
Fix for the implementation of Collection Element
weierophinney added a commit that referenced this pull request Mar 3, 2014
- To retain BC with existing code that implemented it. Marked as deprecated.
weierophinney added a commit that referenced this pull request Mar 3, 2014
Forward port #5636

Conflicts:
	library/Zend/Form/Element/Collection.php
	library/Zend/Form/Fieldset.php
thestanislav added a commit to thestanislav/zf2 that referenced this pull request Apr 9, 2014
$values[$name][$childName] = $fieldset->extract();
}
foreach ($values as $name => $object) {
$fieldset = $this->addNewTargetElementInstance($name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line makes this issue #6118

@stldo stldo deleted the form-collection-fix branch May 13, 2014 14:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants