Merge remote branch 'vicb/form-field'

* vicb/form-field:
  [Form] Tweak the field type
This commit is contained in:
Fabien Potencier 2011-05-22 08:29:54 +02:00
commit 2d2de7e8b0

View File

@ -57,21 +57,28 @@ class FieldType extends AbstractType
public function buildView(FormView $view, FormInterface $form) public function buildView(FormView $view, FormInterface $form)
{ {
$name = $form->getName();
if ($view->hasParent()) { if ($view->hasParent()) {
$parentId = $view->getParent()->get('id'); $parentId = $view->getParent()->get('id');
$parentName = $view->getParent()->get('full_name'); $parentFullName = $view->getParent()->get('full_name');
$id = sprintf('%s_%s', $parentId, $form->getName()); $id = sprintf('%s_%s', $parentId, $name);
$name = sprintf('%s[%s]', $parentName, $form->getName()); $fullName = sprintf('%s[%s]', $parentFullName, $name);
} else { } else {
$id = $form->getName(); $id = $name;
$name = $form->getName(); $fullName = $name;
}
$types = array();
foreach (array_reverse((array) $form->getTypes()) as $type) {
$types[] = $type->getName();
} }
$view $view
->set('form', $view) ->set('form', $view)
->set('id', $id) ->set('id', $id)
->set('name', $form->getName()) ->set('name', $name)
->set('full_name', $name) ->set('full_name', $fullName)
->set('errors', $form->getErrors()) ->set('errors', $form->getErrors())
->set('value', $form->getClientData()) ->set('value', $form->getClientData())
->set('read_only', $form->isReadOnly()) ->set('read_only', $form->isReadOnly())
@ -82,13 +89,8 @@ class FieldType extends AbstractType
->set('label', $form->getAttribute('label')) ->set('label', $form->getAttribute('label'))
->set('multipart', false) ->set('multipart', false)
->set('attr', array()) ->set('attr', array())
->set('types', $types)
; ;
$types = array();
foreach (array_reverse((array) $form->getTypes()) as $type) {
$types[] = $type->getName();
}
$view->set('types', $types);
} }
public function getDefaultOptions(array $options) public function getDefaultOptions(array $options)