I have a mongodb doctrine document that I have converted into a form. The document contains two emebedOne documents, which are also in the form. The main document is checked, but the embedded documents are not. I use custom statements, but I don't think this is important.
Document
class AccountRecord {
/ **
* @MongoDB \ Id
* /
private $ id;
/ **
* @MongoDB \ Field (type = "BimcoreEmail")
* @Assert \ Email
* @Assert \ NotNull
* @CustomAssert \ BimcoreEmail
* /
private $ email;
/ **
* Access Admin
*
* @MongoDB \ Boolean
* /
private $ access_admin = 0;
/ ** @MongoDB \ EmbedOne (targetDocument = "vidAccountSettings") * /
private $ vid;
}
assert .
/** @MongoDB\EmbeddedDocument */
class vidAccountSettings {
/**
* Share section path
*
*
* @MongoDB\Field(type="Url")
* @CustomAssert\Url
*/
private $sharePath;
}
class AccountEditFormType extends AbstractType
{
/**
* Builds the embedded form representing the user.
*
* @param FormBuilder $builder
* @param array $options
*/
public function buildForm(FormBuilder $builder, array $options){
$builder
->add('prefix', 'hidden', array('required' => false))
->add('vid.access', 'checkbox', array('required' => false))
->add('vid.googleAnalytics', 'text', array('required' => false))
->add('vid.liveRail', 'text', array('required' => false))
->add('vid.sharePath', 'url', array('required' => false))
;
}
public function getDefaultOptions(array $options)
{
return array(
'intention' => 'editAccount',
'cascade_validation' => true,
);
}
public function getName()
{
return 'bimfs_account_creation';
}
}class AccountEditFormHandler
{
protected $request;
protected $userManager;
protected $form;
public function __construct(Form $form, Request $request, BimcoreAccountManager $accountManager)
{
$this->form = $form;
$this->request = $request;
$this->accountManager = $accountManager;
}
public function process($account)
{
// set the data in the form for the current account.
$this->form->setData($account);
if ('POST' === $this->request->getMethod()) {
$this->form->bindRequest($this->request);
if ($this->form->isValid()) {
$this->onSuccess($account);
return true;
} else {
}
}
return false;
}
protected function onSuccess(BimcoreAccountRecord $account)
{
// update the account data.
$this->accountManager->updateAccount($account);
}
}
.