8000 [WIP][2.1][Form] Revert some BC breaks by vicb · Pull Request #4134 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[WIP][2.1][Form] Revert some BC breaks #4134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Prev Previous commit
Next Next commit
[Form] Revert "merged branch helmer/readonly_fix (PR #3258)"
This reverts commit 5251177, reversing
changes made to ffef177.
  • Loading branch information
vicb committed Apr 27, 2012
commit 43604e22b5d50564ddbb78e92a4030ee727d5904
24 changes: 11 additions & 13 deletions src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
Original file line number Diff line number Diff line change
Expand Up 8000 @@ -206,23 +206,21 @@ private function addSubFields(FormBuilder $builder, array $choiceViews, array $o
if (is_array($choiceView)) {
// Flatten groups
$this->addSubFields($builder, $choiceView, $options);
} else {
$choiceOpts = array(
} elseif ($options['multiple']) {
$builder->add((string) $i, 'checkbox', array(
'value' => $choiceView->getValue(),
'label' => $choiceView->getLabel(),
'translation_domain' => $options['translation_domain'],
);

if ($options['multiple']) {
$choiceType = 'checkbox';
// The user can check 0 or more checkboxes. If required
// is true, he is required to check all of them.
$choiceOpts['required'] = false;
} else {
$choiceType = 'radio';
}

$builder->add((string) $i, $choiceType, $choiceOpts);
'required' => false,
'translation_domain' => $options['translation_domain'],
));
} else {
$builder->add((string) $i, 'radio', array(
'value' => $choiceView->getValue(),
'label' => $choiceView->getLabel(),
'translation_domain' => $options['translation_domain'],
));
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/Symfony/Component/Form/Extension/Core/Type/FieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public function buildForm(FormBuilder $builder, array $options)
public function buildView(FormView $view, FormInterface $form)
{
$name = $form->getName();
$readOnly = $form->getAttribute('read_only');

if ($view->hasParent()) {
if ('' === $name) {
Expand All @@ -88,9 +87,6 @@ public function buildView(FormView $view, FormInterface $form)
$id = $name;
$fullName = $name;
}

// Complex fields are read-only if themselves or their parent is.
$readOnly = $readOnly || $view->getParent()->get('read_only');
} else {
$id = $name;
$fullName = $name;
Expand All @@ -111,9 +107,9 @@ public function buildView(FormView $view, FormInterface $form)
->set('id', $id)
->set('name', $name)
->set('full_name', $fullName)
->set('read_only', $readOnly)
->set('errors', $form->getErrors())
->set('value', $form->getClientData())
->set('read_only', $form->getAttribute('read_only'))
->set('disabled', $form->isDisabled())
->set('required', $form->isRequired())
->set('max_length', $form->getAttribute('max_length'))
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function getData()
}

/**
* Set whether the form is disabled.
* Set whether the form is disabled
*
* @param Boolean $disabled Whether the form is disabled
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,33 +144,6 @@ public function testPassIdAndNameToViewWithGrandParent()
$this->assertEquals('parent[child][grand_child]', $view['child']['grand_child']->get('full_name'));
}

public function testNonReadOnlyFieldWithReadOnlyParentBeingReadOnly()
{
$parent = $this->factory->createNamed('field', 'parent', null, array('read_only' => true));
$child = $this->factory->createNamed('field', 'child');
$view = $parent->add($child)->createView();

$this->assertTrue($view['child']->get('read_only'));
}

public function testReadOnlyFieldWithNonReadOnlyParentBeingReadOnly()
{
$parent = $this->factory->createNamed('field', 'parent');
$child = $this->factory->createNamed('field', 'child', null, array('read_only' => true));
$view = $parent->add($child)->createView();

$this->assertTrue($view['child']->get('read_only'));
}

public function testNonReadOnlyFieldWithNonReadOnlyParentBeingNonReadOnly()
{
$parent = $this->factory->createNamed('field', 'parent');
$child = $this->factory->createNamed('field', 'child');
$view = $parent->add($child)->createView();

$this->assertFalse($view['child']->get('read_only'));
}

public function testPassMaxLengthToView()
{
$form = $this->factory->create('field', null, array('max_length' => 10));
Expand Down
0