module extensions

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

module extensions

Matus Zeman
Hi there,
I've been thinking recently how one module can extend functionality of another.

Example:
(Let's assume we use DI to get class instances.)

Two modules:
identity - manages system users
contact - adds extra functionality to identity module

Identity form:
  • username
  • password
Contact form:
  • first name
  • surname
  • email
  • ...

1. Contact module needs to add some extra form elements to standard Identity module form. It will do it by adding Contact form as 'contact' subform to identity form.

2. On form submission contact module saves additional data for an identity just created by identity module.

Use case 1
How can we make sure that when identity form instance is created contact form is always added into it?
Three options (what I could think of):
  • Form triggers "init" event
  • DI itself triggers "newInstance" event
  • Using any other strategy how this could be achieved.... what are they?

Use case 2
Contact module subscribes to IdentityService.persist method event and gets $data['identity'] array (returned by $form->getValues() in the controller) and persist them using contact mapper.

What are your thoughts? Could you elaborate on this a bit please?

Matus Zeman
Reply | Threaded
Open this post in threaded view
|

Re: module extensions

SpiffyJr
Look at ZfcUser. EvanDotPro has done something similar for this. He uses a combination of mappers and events to make it work.

Kyle S
"There is a tide in the affairs of men. Which, taken at the flood, leads on to fortune; Omitted, all the voyage of their life Is bound in shallows and in miseries." - WIlliam Shakespeare



On Fri, Mar 2, 2012 at 9:48 AM, Matus Zeman <[hidden email]> wrote:
Hi there,
I've been thinking recently how one module can extend functionality of another.

Example:
(Let's assume we use DI to get class instances.)

Two modules:
identity - manages system users
contact - adds extra functionality to identity module

Identity form:
  • username
  • password
Contact form:
  • first name
  • surname
  • email
  • ...

1. Contact module needs to add some extra form elements to standard Identity module form. It will do it by adding Contact form as 'contact' subform to identity form.

2. On form submission contact module saves additional data for an identity just created by identity module.

Use case 1
How can we make sure that when identity form instance is created contact form is always added into it?
Three options (what I could think of):
  • Form triggers "init" event
  • DI itself triggers "newInstance" event
  • Using any other strategy how this could be achieved.... what are they?

Use case 2
Contact module subscribes to IdentityService.persist method event and gets $data['identity'] array (returned by $form->getValues() in the controller) and persist them using contact mapper.

What are your thoughts? Could you elaborate on this a bit please?

Matus Zeman

Kyle S
blogs @ www.spiffyjr.me
github @ www.github.com/spiffyjr
follow @ www.twitter.com/spiffyjr