zendframework/zf2 — pull request #1694 by bakura10 (2012-07-01 12:43:44+00:00)
Title: Allow fieldsets to have their own hydrator

This PR allows to set hydrator/object on a fieldset basis instead of form basis. This mainly allow to automatically extract/populate compound entities.

There is a use-case in the test with an Address entity that contains a City entities that itself contains a Country entity.

Slight note : I think that most of the time, this feature will be used the following way : each entity will have its own Fieldset, and Form will most of the time "compose" a fieldset (for instance, a User entity that have a UserProfile entity will be bound to one User fieldset that will itself contain a UserProfile fieldset, while the "CreateForm" will just add a User fieldset to it, and eventually exclude unwanted inputs for this particular form using validation groups).

Therefore, the object bounds to the form is not really bound to this form, but rather to the User fieldset. That's why you have to call the function useAsBaseFieldset in a Form object for the specific fieldset you want to use. When this is true, the object given to the form will in fact be bound to the fieldset set as the base fieldset.

Not sure if it's clear ^^.

Some question : I wondered if it made sense to move the Hydrator/object to ElementInterface instead of FieldsetInterface, as most of the time single element will be bound to a single property of an entity, and not be an entity itself.

Furthermore, I didn't try to play with the validation group when you have nested field sets, but for sure it will be really useful (for example, let's say that for a particular form, we only want to show the street and not the city, it would be cool if we could completely add a whole field set or elements of a subfieldset, to a validation work). But it may work, I didn't try tbh.