Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix type guesser. Ignore field MappingException. #458

Merged
merged 1 commit into from
Apr 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Form/DoctrineMongoDBTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Symfony\Component\Form\Guess\Guess;
use Symfony\Component\Form\Guess\TypeGuess;
use Symfony\Component\Form\Guess\ValueGuess;
use Symfony\Component\HttpKernel\Kernel;

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

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

if (! $metadata->hasField($property)) {
return;
}

if ($metadata->hasAssociation($property)) {
$multiple = $metadata->isCollectionValuedAssociation($property);
$mapping = $metadata->getFieldMapping($property);
Expand Down
2 changes: 2 additions & 0 deletions Tests/Fixtures/Form/Guesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ class Guesser

/** @ODM\Field(type="collection") */
public $collectionField;

public $nonMappedField;
}
1 change: 1 addition & 0 deletions Tests/Form/Type/GuesserTestType.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('intField')
->add('integerField')
->add('collectionField')
->add('nonMappedField')
;
}

Expand Down
1 change: 1 addition & 0 deletions Tests/Form/Type/TypeGuesserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function testTypesShouldBeGuessedCorrectly()
$this->assertType('integer', $form->get('intField'));
$this->assertType('integer', $form->get('integerField'));
$this->assertType('collection', $form->get('collectionField'));
$this->assertType('text', $form->get('nonMappedField'));
}

protected function assertType($type, $form)
Expand Down