1
votes

I'm having a small problem with embedForm using doctrine and SF1.4

I have created an module, that a user can edit/create/delete users from a specific group using sfDoctrineGuard

The form is simply a custom form named manufacturerForm.class.php and it extends sfGuardUserAdminForm

class manaufacturerForm extends sfGuardUserAdminForm
{
 public function configure()
 {
     $form = new sfGuardUserProfileForm();
     $this->embedForm('profile', $form);

     unset($this['firstname'], //this field is in sfGuardUserProfile is shown in form
           $this['user_id'],   //this field is in sfGuardUserProfile is shown in form
           $this['is_super_admin'], //this field is in sfGuardUser is not shown
           $this['is_admin'], // this filed is in sfGuardUser is not shown
           $this['permissions_list'], //this field is in sfGuardUser is not shown
           $this['groups_list']);//this field is in sfGuardUser is not shown
  }
}

You can see i am embedding the sfGuardUserProfileForm inside my manufacturerForm.

I have 2 problems, the sfGuardUserProfile has fields that I don't want to display for this particular form, such as: firstname, lastname, email_new, created_at, updated_at, but I can't seem to unset them as they still display.

Note, that this admin module does not have a generator.yml file. I'm doing all of this in editSuccess.php and using a _form.php partial.

My other problem is, when I edit an existing user and save all is well. The problem comes with when I try to edit as I get the following:

An object with the same "user_id" already exist. - this is for the user_id field in sfGuardUserProfile, the same goes for the email_new field. I get An object with the same "email_new" already exist.

1) How do I unset the fields that I don't need?

2) Do I need to overwrite any doSave(), updateObject(), saveEmbeddedForms() methods to stop the last problem?

Thanks

1

1 Answers

1
votes

To remove the fields from the embedded form you need to do this within the form sfGuardUserProfileForm. This is because the fields are read only when embedded into the manufacturerForm.

If you need to remove custom fields from the sfGuardUserProfileForm that you normally wouldn't do, simply extend the class, remove the fields there and embed the new extended form.

When you are embedding the form you need to pass in the existing sfGuardUserPofile object.

class manaufacturerForm extends sfGuardUserAdminForm
{
    public function configure()
    {
        $form = new manaufacturerProfileForm($this->getObject()->getProfile());
        $this->embedForm('profile', $form);
    }
}


class manaufacturerProfileForm extends sfGuardUserProfileForm
{
    public function configure()
    {
        unset($this['firstname'], //this field is in sfGuardUserProfile is shown in form
              $this['user_id'],   //this field is in sfGuardUserProfile is shown in form
              $this['is_super_admin'], //this field is in sfGuardUser is not shown
              $this['is_admin'], // this filed is in sfGuardUser is not shown
              $this['permissions_list'], //this field is in sfGuardUser is not shown
              $this['groups_list']);//this field is in sfGuardUser is not shown
     }