I have a Doctrine mongodb document that I have turned into a form. The document has two emebedOne documents, that are also in the form. The main document is being validated, but the embed docs are not. I am using custom asserts but I don't think that should matter.
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;
}
embeded class the custom assert on this is never called.
/** @MongoDB\EmbeddedDocument */
class vidAccountSettings {
/**
* Share section path
*
*
* @MongoDB\Field(type="Url")
* @CustomAssert\Url
*/
private $sharePath;
}
form
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';
}
}
handler
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);
}
}
Thanks for the help.
Cory