SOLVED.
I seem to should not have use the collection form.
And I seem to should use to "->add('profile', new ProfileType())
".
hope this helps
Entity/Profile.php
namespace My\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="My\UserBundle\Repository\UserRepository")
*/
class Profile
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $website;
// .... and other profile
/**
* @ORM\OneToOne(targetEntity="User", mappedBy="profile", cascade={"persist", "merge", "remove"})
*/
protected $user;
// ....
}
Entity/User.php
// ...
/**
* @ORM\OneToOne(targetEntity="Profile", inversedBy="user", cascade={"persist", "merge", "remove"})
* @ORM\JoinColumn(referencedColumnName="id")
*/
protected $profile;
public function setProfile(Profile $profile)
{
$this->profile = $profile;
}
public function getProfile()
{
return $this->profile;
}
Controller/ProfileController
public function editAction()
{
$em = $this->container->get('doctrine')->getManager();
$own = $this->container->get('security.context')->getToken()->getUser();
$user = $em->getRepository('MyUserBundle:User')->find_one_with_info($own); //=> Left join profile table
if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
}
if (! $user->getProfile())
$user->setProfile(new Profile());
$form = $this->container->get('fos_user.profile.form');
$formHandler = $this->container->get('fos_user.profile.form.handler');
$process = $formHandler->process($user);
// ...
Form/Type/ProfileType
// ...
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('website', 'text', array('required' => false))
// ... and other profile
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'My\UserBundle\Entity\Profile',
));
}
// ...
Form/Type/ProfileFormType
// ...
protected function buildUserForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle'))
->add('profile', new ProfileType())
;
}
// ...
View/Profile/edit_content.html.twig
// ...
<div>
{{ form_errors(form.profile.website) }}
</div>
<div>
<label>Website:</label>
{{ form_widget(form.profile.website) }}
</div>
// ... and other profile
<div>
{{ form_errors(form.current_password) }}
</div>
<div>
{{ form_label(form.current_password) }}
{{ form_widget(form.current_password) }}
</div>
{{ form_widget(form) }}
// ...