Hi,

tl;dr: I want to make some changes to the ZF AnnotationBuilder and Form
sources and would appreciate some feedback.

I've been greatly intrigued with the AnnotationBuilder feature to allow
me to configure the editing form of an entity in the very same entity.
In particular with the DoctrineModule and -Hydrator it's now possible to
configure everything about an entity in one place, e.g. if the db column
is Varchar(32) immediately configure the input validators to now allow
more than 32 characters, etc.

Unfortunately I've also encountered some limitations which I found to be
mostly due to the fact that the AB is a comparatively new feature. I'd
like to address some of these limitations and also provide the solutions
(Pull Requests) if accepted.

The biggest problem I encountered is that forms can't have subforms.
Technically there is no problem as forms are also fieldsets and can be
added just like these, but the devil is in the details. So why is this
needed for the AnnotationBuilder?
Here's a use case:
https://github.com/CrisMKM/zf2FormTesting

Say you have a user entity with the annotations configured to create a
form to edit it.
But depending on context you want to edit it differently:
On Registration you want to edit different things as when a registered
user wants to edit his profile and again another edit view for an
administrator managing users.

In each of these cases you want to bind a user object to the form and
after validation get a newly configured user to store in database or
wherever.

1. For Registration you'd only ask for the username, email and password
as well as a password repeat and attach custom validators to prevent
duplicate usernames and emails.

2. A user editing his account details you'd deny editing the username
and would require the current password to change any details.

3. The administrator would be able to edit the user just like he wants,
except for some fields like registration date, last login, etc.

For each of these cases I'd create a new action form class, make the
AnnotationBuilder create the User entity form, place it on my action
form and have it take appropriate measures to resemble the cases above,
like adding or eliminating elements, filters and validators.

I've already extended the AnnotationBuilder class locally to take care
of some of these changes and it works great. But my biggest problem is
that forms aren't really designed to have other forms in the fieldset
arrays, in particular when it comes to validation, namely:
Form::attachInputFilterDefaults() doesn't attach InputFilters of
subforms and
Form::bindValues() doesn't return the object as does
Fieldset::bindValues() and also causes the form values to be set to the
bound object multiple times.

I do have some more issues and suggestions but don't want to make this
too long. Please let me know if there's some fundamental flaw in my idea
or what could be done better/differently. I'll gladly provide the codes
to the zf github repos.

Best regards,
Cristian



-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com


Reply via email to