Example #1
0
 /**
  * Merges current form widget and validator schemas with the ones from the
  * sfForm object passed as parameter. Please note it also merge defaults.
  *
  * @param  sfForm   $form      The sfForm instance to merge with current form
  *
  * @throws \LogicException      If one of the form has already been bound
  */
 public function mergeForm(Form $form)
 {
     if (true === $this->isBound() || true === $form->isBound()) {
         throw new \LogicException('A bound form cannot be merged');
     }
     $form = clone $form;
     unset($form[self::$CSRFFieldName]);
     $this->defaults = array_merge($this->defaults, $form->getDefaults());
     foreach ($form->getWidgetSchema()->getPositions() as $field) {
         $this->widgetSchema[$field] = $form->getWidget($field);
     }
     foreach ($form->getValidatorSchema()->getFields() as $field => $validator) {
         $this->validatorSchema[$field] = $validator;
     }
     $this->getWidgetSchema()->setLabels(array_merge($this->getWidgetSchema()->getLabels(), $form->getWidgetSchema()->getLabels()));
     $this->getWidgetSchema()->setHelps(array_merge($this->getWidgetSchema()->getHelps(), $form->getWidgetSchema()->getHelps()));
     $this->mergePreValidator($form->getValidatorSchema()->getPreValidator());
     $this->mergePostValidator($form->getValidatorSchema()->getPostValidator());
     $this->resetFormFields();
 }