Skip to content

Commit d40fc1a

Browse files
authored
Merge pull request #458 from BoShurik/type-guesser-fix
Fix type guesser. Ignore field MappingException.
2 parents 2e17907 + 5c4aba6 commit d40fc1a

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

Form/DoctrineMongoDBTypeGuesser.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Symfony\Component\Form\Guess\Guess;
1818
use Symfony\Component\Form\Guess\TypeGuess;
1919
use Symfony\Component\Form\Guess\ValueGuess;
20-
use Symfony\Component\HttpKernel\Kernel;
2120

2221
/**
2322
* Tries to guess form types according to ODM mappings
@@ -44,11 +43,15 @@ public function __construct(ManagerRegistry $registry)
4443
public function guessType($class, $property)
4544
{
4645
if (!$ret = $this->getMetadata($class)) {
47-
return new TypeGuess($this->typeFQCN ? TextType::class : 'text', [], Guess::LOW_CONFIDENCE);
46+
return;
4847
}
4948

5049
list($metadata, $name) = $ret;
5150

51+
if (! $metadata->hasField($property)) {
52+
return;
53+
}
54+
5255
if ($metadata->hasAssociation($property)) {
5356
$multiple = $metadata->isCollectionValuedAssociation($property);
5457
$mapping = $metadata->getFieldMapping($property);

Tests/Fixtures/Form/Guesser.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,6 @@ class Guesser
4747

4848
/** @ODM\Field(type="collection") */
4949
public $collectionField;
50+
51+
public $nonMappedField;
5052
}

Tests/Form/Type/GuesserTestType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
2626
->add('intField')
2727
->add('integerField')
2828
->add('collectionField')
29+
->add('nonMappedField')
2930
;
3031
}
3132

Tests/Form/Type/TypeGuesserTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function testTypesShouldBeGuessedCorrectly()
7070
$this->assertType('integer', $form->get('intField'));
7171
$this->assertType('integer', $form->get('integerField'));
7272
$this->assertType('collection', $form->get('collectionField'));
73+
$this->assertType('text', $form->get('nonMappedField'));
7374
}
7475

7576
protected function assertType($type, $form)

0 commit comments

Comments
 (0)