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();
 }
Example #2
0
$t->is($f->renderUsing('list'), fix_linebreaks($output), 'renderUsing() renders the widget schema using the given form formatter');
$t->is($f->getWidgetSchema()->getFormFormatterName(), 'table', 'renderUsing() does not persist form formatter name for the current form instance');
$w = $f->getWidgetSchema();
$w->addFormFormatter('custom', new WidgetSchemaFormatterList($w));
$t->is($f->renderUsing('custom'), fix_linebreaks($output), 'renderUsing() renders a custom form formatter');
try {
    $f->renderUsing('nonexistant');
    $t->fail('renderUsing() throws an exception if formatter name does not exist');
} catch (\InvalidArgumentException $e) {
    $t->pass('renderUsing() throws an exception if formatter name does not exist');
} catch (\Exception $e) {
    $t->pass('renderUsing() throws an exception if formatter name does not exist');
}
// renderHiddenFields()
$t->diag('->renderHiddenFields()');
$f = new Form();
$f->setWidgets(array('id' => new WidgetInputHidden(), 'name' => new WidgetInputText(), 'is_admin' => new WidgetInputHidden()));
$output = '<input type="hidden" name="id" id="id" /><input type="hidden" name="is_admin" id="is_admin" />';
$t->is($f->renderHiddenFields(), $output, 'renderHiddenFields() renders all hidden fields, no visible fields');
$t->is(count($f->getFormFieldSchema()), 3, 'renderHiddenFields() does not modify the form fields');
$author = new Form();
$author->setWidgets(array('id' => new WidgetInputHidden(), 'name' => new WidgetInputText()));
$company = new Form();
$company->setWidgets(array('id' => new WidgetInputHidden(), 'name' => new WidgetInputText()));
$author->embedForm('company', $company);
$output = '<input type="hidden" name="id" id="id" /><input type="hidden" name="company[id]" id="company_id" />';
$t->is($author->renderHiddenFields(), $output, 'renderHiddenFields() renders hidden fields from embedded forms');
$output = '<input type="hidden" name="id" id="id" />';
$t->is($author->renderHiddenFields(false), $output, 'renderHiddenFields() does not render hidden fields from embedded forms if the first parameter is "false"');
// ->embedForm()
$t->diag('->embedForm()');