ZfcUserAdmin icon indicating copy to clipboard operation
ZfcUserAdmin copied to clipboard

Binding User to Edit Form fixes issues #30 and #31

Open webdevilopers opened this issue 11 years ago • 2 comments

These changes are just a proposal for solution for the following issues:

  • https://github.com/Danielss89/ZfcUserAdmin/issues/30
  • https://github.com/Danielss89/ZfcUserAdmin/issues/31

I have not edited further code since I can't tell yet what consequences this will have on

  • custom form elements
  • EditUser Form setUser event see https://github.com/Danielss89/ZfcUserAdmin/blob/master/src/ZfcUserAdmin/Form/EditUser.php#L72-76
  • EditUser Form populateFromUser() method see https://github.com/Danielss89/ZfcUserAdmin/blob/master/src/ZfcUserAdmin/Form/EditUser.php#L83-99 and others.

But - similar to binding the User to the CreateUser Form inside the createAction method, this scenario works with Doctrine's ORM with OneToOne and ManyToMany relationships.

Any thoughts, @Danielss89 ?

webdevilopers avatar Jun 11 '14 13:06 webdevilopers

I just recognized that this required the zfcuser_user_hydrator to be set / used.

class Module // forminterface is automatically implemented?
{
    public function onBootstrap(MvcEvent $e)
    {
        $em = $eventManager->getSharedManager();
    $em->attach(
        'ZfcUserAdmin\Form\EditUser',
            'init',
            function($e)
            {
                /* @var $form \ZfcUser\Form\Register */
                $form = $e->getTarget();

                $sm = $form->getServiceManager();
                $om = $sm->get('Doctrine\ORM\EntityManager');

                $form->setHydrator($sm->get('zfcuser_user_hydrator'));
            }
    );
    }
}

I think this can be achieved by setting the hydrator inside the controller the way it currently happens: https://github.com/Danielss89/ZfcUserAdmin/blob/master/src/ZfcUserAdmin/Controller/UserAdminController.php#L50

webdevilopers avatar Jun 11 '14 13:06 webdevilopers

I have added the zfcuser_user_hydrator inside the controllers actions.

webdevilopers avatar Jun 11 '14 13:06 webdevilopers