mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-03-12 10:36:09 +03:00
Added support for Doctrine MongoDB ODM 'document' form type (#1377)
* Added support for Doctrine MongoDB ODM 'document' form type * Simplify code
This commit is contained in:
parent
63cee64e6b
commit
309f935763
@ -177,12 +177,14 @@ final class FormModelDescriber implements ModelDescriberInterface, ModelRegistry
|
||||
break;
|
||||
}
|
||||
|
||||
if ('entity' === $blockPrefix) {
|
||||
// The DocumentType is bundled with the DoctrineMongoDBBundle
|
||||
if ('entity' === $blockPrefix || 'document' === $blockPrefix) {
|
||||
$entityClass = $config->getOption('class');
|
||||
|
||||
if ($config->getOption('multiple')) {
|
||||
$property->setFormat(sprintf('[%s id]', $entityClass));
|
||||
$property->setType('array');
|
||||
$property->getItems()->setType('string');
|
||||
} else {
|
||||
$property->setType('string');
|
||||
$property->setFormat(sprintf('%s id', $entityClass));
|
||||
@ -223,7 +225,7 @@ final class FormModelDescriber implements ModelDescriberInterface, ModelRegistry
|
||||
return null;
|
||||
}
|
||||
|
||||
if ('entity' === $type->getBlockPrefix()) {
|
||||
if ('entity' === $type->getBlockPrefix() || 'document' === $type->getBlockPrefix()) {
|
||||
return $type;
|
||||
}
|
||||
|
||||
|
30
Tests/Functional/Form/DocumentType.php
Normal file
30
Tests/Functional/Form/DocumentType.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the NelmioApiDocBundle package.
|
||||
*
|
||||
* (c) Nelmio
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Nelmio\ApiDocBundle\Tests\Functional\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class DocumentType extends AbstractType
|
||||
{
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setRequired('class');
|
||||
}
|
||||
|
||||
public function getParent(): string
|
||||
{
|
||||
return ChoiceType::class;
|
||||
}
|
||||
}
|
@ -37,6 +37,9 @@ class UserType extends AbstractType
|
||||
])
|
||||
->add('quz', DummyType::class, ['documentation' => ['type' => 'string', 'description' => 'User type.'], 'required' => false])
|
||||
->add('entity', EntityType::class, ['class' => 'Entity'])
|
||||
->add('entities', EntityType::class, ['class' => 'Entity', 'multiple' => true])
|
||||
->add('document', DocumentType::class, ['class' => 'Document'])
|
||||
->add('documents', DocumentType::class, ['class' => 'Document', 'multiple' => true])
|
||||
->add('extended_builtin', ExtendedBuiltinType::class, ['required_option' => 'foo']);
|
||||
}
|
||||
|
||||
|
@ -248,12 +248,26 @@ class FunctionalTest extends WebTestCase
|
||||
'type' => 'string',
|
||||
'format' => 'Entity id',
|
||||
],
|
||||
'entities' => [
|
||||
'type' => 'array',
|
||||
'format' => '[Entity id]',
|
||||
'items' => ['type' => 'string'],
|
||||
],
|
||||
'document' => [
|
||||
'type' => 'string',
|
||||
'format' => 'Document id',
|
||||
],
|
||||
'documents' => [
|
||||
'type' => 'array',
|
||||
'format' => '[Document id]',
|
||||
'items' => ['type' => 'string'],
|
||||
],
|
||||
'extended_builtin' => [
|
||||
'type' => 'string',
|
||||
'enum' => ['foo', 'bar'],
|
||||
],
|
||||
],
|
||||
'required' => ['dummy', 'dummies', 'entity', 'extended_builtin'],
|
||||
'required' => ['dummy', 'dummies', 'entity', 'entities', 'document', 'documents', 'extended_builtin'],
|
||||
], $this->getModel('UserType')->toArray());
|
||||
|
||||
$this->assertEquals([
|
||||
|
Loading…
x
Reference in New Issue
Block a user