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

Hotfix/multiple nested collection test #5495

Closed
wants to merge 6 commits into from
Closed

Hotfix/multiple nested collection test #5495

wants to merge 6 commits into from

Conversation

fabiocarneiro
Copy link
Contributor

Tests for making sure we can bind objects to multiple fieldsets and collections

public function testCanBindObjectMultipleNestedFieldsets()
{

$productFieldset = new \ZendTest\Form\TestAsset\ProductFieldset();
Copy link
Member

Choose a reason for hiding this comment

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

please import the classes using use statements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've copied it from the function above. The class is full of that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Maks3w There it is!

$shop[1] = new stdClass();
$shop[1]->products = $products;

$market->collection = $shop;
Copy link
Contributor

Choose a reason for hiding this comment

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

I do no see any element named "collection" in the form

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right!

),
));

$mainFieldset = new Fieldset('main');
Copy link
Contributor

Choose a reason for hiding this comment

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

And once again, $mainFieldset should be Collection according to the object. You've mixed up with fieldsets and binding object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Form has a mainFieldset, that has a collection of nestedFieldset, that has a collection of productFieldset. the missing part is useasbasefieldset.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be something like this

$form = new Form();
$form->setHydrator(new ObjectPropertyHydrator());

$form->add(array(
            'name' => 'main',
            'type' => 'Collection',
            'options' => array(
                'target_element' => $nestedFieldset,
                'count' => 2
            ),
));

Copy link
Contributor

Choose a reason for hiding this comment

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

Assume this:
Fieldset = object
Collection = array/Traversable
Element = object property/class method

Copy link
Contributor

Choose a reason for hiding this comment

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

$market -> $form
$shop -> "main" fieldset but should be a collection
????? -> "nested" collection
.....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to achieve two levels of collections.
Form
--> Fieldset
--> --> Collection
--> --> --> Fieldset
--> --> --> --> Collection
--> --> --> --> --> Fieldset

@thestanislav
Copy link
Contributor

I think i understand your issue.
As I know you should always bind an empty objects to your fieldsets. Look this https://github.com/zendframework/zf2/blob/master/tests/ZendTest/Form/TestAsset/ProductFieldset.php#L23

So you should do something like these

$nestedFieldset = new Fieldset('nested');
$nestedFieldset = new Fieldset('nested');
$nestedFieldset->setHydrator(new ClassMethods());
$nestedFieldset->setObject(new Stdclass()); // or what ever you object is

....
....
....
$mainFieldset = new Fieldset('main');
$mainFieldset->setHydrator(new ClassMethods());
$mainFieldset->setObject(new Stdclass()); // or what ever you object is

Otherwise nested objects would not bound to appropriate fieldsets

@fabiocarneiro
Copy link
Contributor Author

I'm not doing it in the test, but i am doing in my actual code. If you could test it, it would be really awesome. I know its a bit too much to ask, but i'm on that issue for more than one week and i really need it working to move ahead.
https://github.com/fabiocarneiro/FhcsFormTest

I'ts a really simplified use case with only the necessary things.

Nested objects should be bound to the appropriate fieldsets, if its not doing it right now, it should be fixed, and i've been working hard to fix that, with no success.

@weierophinney
Copy link
Member

@fabiocarneiro Have you been able to investigate this any further? Perhaps ping Bakura in #zftalk.dev on Freenode IRC to see if he can assist.

weierophinney added a commit that referenced this pull request Mar 3, 2014
- Unit test passes now, meaning we can close both issues.
@weierophinney weierophinney added this to the 2.2.6 milestone Mar 3, 2014
@weierophinney weierophinney self-assigned this Mar 3, 2014
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.

4 participants