public function buildForm(FormBuilderInterface $builder, array $options) { /** @var \Wealthbot\RiaBundle\Entity\RiaCompanyInformation $info */ $info = $this->user->getRiaCompanyInformation(); if ($info) { $name = $info->getName() ? $info->getName() : $this->user->getProfile()->getCompany(); $primaryFirstName = $info->getPrimaryFirstName() ? $info->getPrimaryFirstName() : $this->user->getProfile()->getFirstName(); $primaryLastName = $info->getPrimaryLastName() ? $info->getPrimaryLastName() : $this->user->getProfile()->getLastName(); $contactEmail = $info->getContactEmail() ? $info->getContactEmail() : $this->user->getEmail(); } else { $name = $this->user->getProfile()->getCompany(); $primaryFirstName = $this->user->getProfile()->getFirstName(); $primaryLastName = $this->user->getProfile()->getLastName(); $contactEmail = $this->user->getEmail(); } $builder->add('name', 'text', array('data' => $name, 'required' => false))->add('slug', 'text', array('required' => true))->add('primary_first_name', 'text', array('data' => $primaryFirstName, 'required' => false))->add('primary_last_name', 'text', array('data' => $primaryLastName, 'required' => false))->add('website', 'url', array('required' => false))->add('address', 'text', array('required' => false))->add('office', 'text', array('required' => false))->add('city', 'text', array('required' => false))->add('state', 'entity', array('class' => 'WealthbotAdminBundle:State', 'label' => 'State', 'empty_value' => 'Select a State', 'required' => false))->add('zipcode', 'text', array('required' => false))->add('phone_number', 'text', array('required' => false))->add('fax_number', 'text', array('required' => false))->add('contact_email', 'email', array('data' => $contactEmail, 'required' => false)); //Other information $builder->add('min_asset_size', 'number', array('precision' => 2, 'grouping' => true, 'required' => false))->add('logo_file', 'file', array('required' => false)); //Proposal processing $builder->add('portfolio_processing', 'choice', array('choices' => RiaCompanyInformation::getPortfolioProcessingChoices(), 'disabled' => true, 'required' => true, 'expanded' => true)); $this->addValidator($builder); if (!$this->isPreSave) { $this->addOnBindValidator($builder); } }
protected function addOnBindValidator(FormBuilderInterface $builder) { $em = $this->em; $ria = $this->user; $isModels = $this->isModels; $builder->addEventListener(FormEvents::BIND, function (FormEvent $event) use($em, $ria, $isModels) { /** @var $form */ $form = $event->getForm(); /** @var \Wealthbot\RiaBundle\Entity\RiaCompanyInformation $data */ $data = $event->getData(); /** @var $repo CeModelRepository */ $repo = $em->getRepository('WealthbotAdminBundle:CeModel'); /** @var $ceModelEntityRepo CeModelEntityRepository */ $ceModelEntityRepo = $em->getRepository('WealthbotAdminBundle:CeModelEntity'); if ($isModels) { $modelType = $form->get('model_type')->getData(); if (!$modelType) { $form->get('model_type')->addError(new FormError('Required.')); } else { switch ($modelType) { case CeModel::TYPE_STRATEGY: $strategyParentModelId = $form->get('strategy_model')->getData(); if (!$strategyParentModelId) { $form->get('strategy_model')->addError(new FormError('Please specify the model.')); } else { /** @var $strategyParentModel CeModel */ $strategyParentModel = $repo->find($strategyParentModelId); if (!$strategyParentModel) { $form->get('strategy_model')->addError(new FormError('Model does not exist')); } } break; case CeModel::TYPE_CUSTOM: break; default: $form->get('model_type')->addError(new FormError('Type does not exist.')); } } } if ($form->has('portfolio_processing')) { $portfolioProcessing = $data->getPortfolioProcessing(); if (is_null($portfolioProcessing) || !array_key_exists($portfolioProcessing, RiaCompanyInformation::getPortfolioProcessingChoices())) { $form->get('portfolio_processing')->addError(new FormError('Invalid.')); } } if (!$data->getAccountManaged()) { $form->get('account_managed')->addError(new FormError('Required.')); } elseif ($data->isClientByClientManagedLevel() && $data->isStraightThroughProcessing()) { $form->get('account_managed')->addError(new FormError('Must be Account or Household level for Straight Through portfolio processing.')); } if (!$data->getRebalancedMethod()) { $form->get('rebalanced_method')->addError(new FormError('Required.')); } if (!$data->getRebalancedFrequency()) { $form->get('rebalanced_frequency')->addError(new FormError('Required.')); } if ($data->getUseMunicipalBond() && !$data->getClientsTaxBracket()) { $form->get('clients_tax_bracket')->addError(new FormError('Required.')); } // if (!is_numeric($data->getIsShowClientExpectedAssetClass())) { // $form->get('is_show_client_expected_asset_class')->addError(new FormError('Required.')); // } if ($data->getIsTaxLossHarvesting() && !$data->getTaxLossHarvestingMinimumPercent()) { $form->get('tax_loss_harvesting_minimum_percent')->addError(new FormError('Required.')); } if (is_null($data->getIsAllowRetirementPlan())) { $form->get('is_allow_retirement_plan')->addError(new FormError('Required.')); } if (!$data->getUseMunicipalBond() && $ceModelEntityRepo->isMuniBondSecuritiesInRiaModels($ria->getId())) { $form->get('use_municipal_bond')->addError(new FormError('You have "municipal substitution" securities in model.')); } // isTaxLossHarvestingSecuritiesInModels if (!$data->getIsTaxLossHarvesting() && $ceModelEntityRepo->isTaxLossHarvestingSecuritiesInModels($ria->getId())) { $form->get('is_tax_loss_harvesting')->addError(new FormError('You have "tax loss harvesting" securities in model.')); } }); }