Skip to content

Commit

Permalink
Merge pull request #207 from doctrine/fix_form_read_omly_deprecations
Browse files Browse the repository at this point in the history
refactored read_only option for Symfony 2.8
  • Loading branch information
lsmith77 committed Aug 10, 2015
2 parents b04aae1 + 4d02519 commit c5a374d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
10 changes: 5 additions & 5 deletions Form/PhpcrOdmTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function guessType($class, $property)

case 'mixedreferrers':
$options = array(
'read_only' => true,
'attr' => array('readonly' => 'readonly'),
'type' => 'phpcr_odm_path',
);

Expand All @@ -104,14 +104,14 @@ public function guessType($class, $property)

case 'child':
$options = array(
'read_only' => true,
'attr' => array('readonly' => 'readonly'),
);

return new TypeGuess('phpcr_odm_path', $options, Guess::LOW_CONFIDENCE);

case 'children':
$options = array(
'read_only' => true,
'attr' => array('readonly' => 'readonly'),
'type' => 'phpcr_odm_path',
);

Expand Down Expand Up @@ -160,7 +160,7 @@ public function guessType($class, $property)
if ($metadata->isIdentifier($property)
|| $metadata->isUuid($property)
) {
$options['read_only'] = true;
$options['attr'] = array('readonly' => 'readonly');
}
$type = 'text';
break;
Expand All @@ -175,7 +175,7 @@ public function guessType($class, $property)
case 'versionname':
case 'versioncreated':
default:
$options['read_only'] = true;
$options['attr'] = array('readonly' => 'readonly');
$options['required'] = false;
$type = 'text';
break;
Expand Down
26 changes: 6 additions & 20 deletions Tests/Functional/Form/PHPCRTypeGuesserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public function testFields()
$formBuilder->get('bool'),
'\Symfony\Component\Form\Extension\Core\Type\CheckboxType',
array(
'read_only' => false,
'required' => false,
)
);
Expand All @@ -71,7 +70,6 @@ public function testFields()
$formBuilder->get('date'),
'\Symfony\Component\Form\Extension\Core\Type\DateTimeType',
array(
'read_only' => false,
'required' => true,
)
);
Expand All @@ -80,7 +78,6 @@ public function testFields()
$formBuilder->get('text'),
'\Symfony\Component\Form\Extension\Core\Type\TextType',
array(
'read_only' => false,
'required' => true,
)
);
Expand All @@ -89,7 +86,6 @@ public function testFields()
$formBuilder->get('number'),
'\Symfony\Component\Form\Extension\Core\Type\NumberType',
array(
'read_only' => false,
'required' => true,
)
);
Expand All @@ -98,7 +94,6 @@ public function testFields()
$formBuilder->get('integer'),
'\Symfony\Component\Form\Extension\Core\Type\IntegerType',
array(
'read_only' => false,
'required' => true,
)
);
Expand All @@ -107,7 +102,6 @@ public function testFields()
$formBuilder->get('long'),
'\Symfony\Component\Form\Extension\Core\Type\IntegerType',
array(
'read_only' => false,
'required' => true,
)
);
Expand All @@ -133,7 +127,6 @@ public function testMultivalueFields()
'\Symfony\Component\Form\Extension\Core\Type\CollectionType',
array(
'type' => 'checkbox',
'read_only' => false,
'required' => false,
)
);
Expand All @@ -143,7 +136,6 @@ public function testMultivalueFields()
'\Symfony\Component\Form\Extension\Core\Type\CollectionType',
array(
'type' => 'datetime',
'read_only' => false,
'required' => false,
)
);
Expand All @@ -153,7 +145,6 @@ public function testMultivalueFields()
'\Symfony\Component\Form\Extension\Core\Type\CollectionType',
array(
'type' => 'text',
'read_only' => false,
'required' => false,
)
);
Expand All @@ -163,7 +154,6 @@ public function testMultivalueFields()
'\Symfony\Component\Form\Extension\Core\Type\CollectionType',
array(
'type' => 'number',
'read_only' => false,
'required' => false,
)
);
Expand All @@ -173,7 +163,6 @@ public function testMultivalueFields()
'\Symfony\Component\Form\Extension\Core\Type\CollectionType',
array(
'type' => 'integer',
'read_only' => false,
'required' => false,
)
);
Expand All @@ -183,7 +172,6 @@ public function testMultivalueFields()
'\Symfony\Component\Form\Extension\Core\Type\CollectionType',
array(
'type' => 'integer',
'read_only' => false,
'required' => false,
)
);
Expand All @@ -208,7 +196,7 @@ public function testHierarchy()
$formBuilder->get('id'),
'\Symfony\Component\Form\Extension\Core\Type\TextType',
array(
'read_only' => true,
'attr' => array('readonly' => 'readonly'),
'required' => false,
)
);
Expand All @@ -217,7 +205,6 @@ public function testHierarchy()
$formBuilder->get('parent'),
'Doctrine\Bundle\PHPCRBundle\Form\Type\PathType',
array(
'read_only' => false,
'required' => true,
)
);
Expand All @@ -226,7 +213,6 @@ public function testHierarchy()
$formBuilder->get('nodename'),
'\Symfony\Component\Form\Extension\Core\Type\TextType',
array(
'read_only' => false,
'required' => true,
)
);
Expand All @@ -235,7 +221,7 @@ public function testHierarchy()
$formBuilder->get('uuid'),
'\Symfony\Component\Form\Extension\Core\Type\TextType',
array(
'read_only' => true,
'attr' => array('readonly' => 'readonly'),
'required' => false,
)
);
Expand All @@ -244,7 +230,7 @@ public function testHierarchy()
$formBuilder->get('child'),
'Doctrine\Bundle\PHPCRBundle\Form\Type\PathType',
array(
'read_only' => true,
'attr' => array('readonly' => 'readonly'),
'required' => false,
)
);
Expand All @@ -253,7 +239,7 @@ public function testHierarchy()
$formBuilder->get('children'),
'\Symfony\Component\Form\Extension\Core\Type\CollectionType',
array(
'read_only' => true,
'attr' => array('readonly' => 'readonly'),
'required' => false,
'type' => 'phpcr_odm_path',
)
Expand Down Expand Up @@ -337,7 +323,7 @@ public function testReferrers()
$formBuilder->get('mixedReferrers'),
'\Symfony\Component\Form\Extension\Core\Type\CollectionType',
array(
'read_only' => true,
'attr' => array('readonly' => 'readonly'),
'required' => false,
'type' => 'phpcr_odm_path',
)
Expand Down Expand Up @@ -373,7 +359,7 @@ private function assertFormType(FormBuilderInterface $element, $typeClass, array
$type = $element->getType()->getInnerType();
$this->assertInstanceOf($typeClass, $type);
foreach ($options as $option => $expected) {
$this->assertEquals($expected, $element->getOption($option), "Option '$option' does not have the expected value '$expected'");
$this->assertEquals($expected, $element->getOption($option), "Option '$option' does not have the expected value '".serialize($expected)."'");
}
}
}

0 comments on commit c5a374d

Please sign in to comment.