mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 23:59:26 +03:00
commit
82813e1ae1
@ -15,8 +15,9 @@ use Symfony\Component\Form\AbstractTypeExtension;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormViewInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||
|
||||
class DescriptionFieldTypeExtension extends AbstractTypeExtension
|
||||
class DescriptionFormTypeExtension extends AbstractTypeExtension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@ -31,17 +32,17 @@ class DescriptionFieldTypeExtension extends AbstractTypeExtension
|
||||
*/
|
||||
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->set('description', $form->getAttribute('description'));
|
||||
$view->setVar('description', $options['description']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
return array(
|
||||
$resolver->setDefaults(array(
|
||||
'description' => '',
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,6 +50,6 @@ class DescriptionFieldTypeExtension extends AbstractTypeExtension
|
||||
*/
|
||||
public function getExtendedType()
|
||||
{
|
||||
return 'field';
|
||||
return 'form';
|
||||
}
|
||||
}
|
@ -52,18 +52,14 @@ class FormTypeParser
|
||||
*/
|
||||
public function parse(AbstractType $type)
|
||||
{
|
||||
$builder = $this->formFactory->createBuilder($type);
|
||||
$form = $this->formFactory->create($type);
|
||||
|
||||
$parameters = array();
|
||||
foreach ($builder->all() as $name => $child) {
|
||||
if ($child instanceof FormBuilder) {
|
||||
$childBuilder = $child;
|
||||
} else {
|
||||
$childBuilder = $builder->create($name, $child['type'] ?: 'text', $child['options']);
|
||||
}
|
||||
foreach ($form as $name => $child) {
|
||||
$config = $child->getConfig();
|
||||
|
||||
$bestType = '';
|
||||
foreach ($childBuilder->getTypes() as $type) {
|
||||
foreach ($config->getTypes() as $type) {
|
||||
if (isset($this->mapTypes[$type->getName()])) {
|
||||
$bestType = $this->mapTypes[$type->getName()];
|
||||
}
|
||||
@ -71,8 +67,8 @@ class FormTypeParser
|
||||
|
||||
$parameters[$name] = array(
|
||||
'dataType' => $bestType,
|
||||
'required' => $childBuilder->getRequired(),
|
||||
'description' => $childBuilder->getAttribute('description'),
|
||||
'required' => $config->getRequired(),
|
||||
'description' => $config->getAttribute('description'),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
<parameters>
|
||||
<parameter key="nelmio_api_doc.extractor.api_doc_extractor.class">Nelmio\ApiDocBundle\Extractor\ApiDocExtractor</parameter>
|
||||
<parameter key="nelmio_api_doc.form.extension.description_field_type_extension.class">Nelmio\ApiDocBundle\Form\Extension\DescriptionFieldTypeExtension</parameter>
|
||||
<parameter key="nelmio_api_doc.form.extension.description_form_type_extension.class">Nelmio\ApiDocBundle\Form\Extension\DescriptionFormTypeExtension</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
@ -14,8 +14,8 @@
|
||||
<argument type="service" id="router" />
|
||||
<argument type="service" id="annotation_reader" />
|
||||
</service>
|
||||
<service id="nelmio_api_doc.form.extension.description_field_type_extension" class="%nelmio_api_doc.form.extension.description_field_type_extension.class%">
|
||||
<tag name="form.type_extension" alias="field" />
|
||||
<service id="nelmio_api_doc.form.extension.description_form_type_extension" class="%nelmio_api_doc.form.extension.description_form_type_extension.class%">
|
||||
<tag name="form.type_extension" alias="form" />
|
||||
</service>
|
||||
</services>
|
||||
|
||||
|
@ -13,6 +13,7 @@ namespace Nelmio\ApiDocBundle\Tests\Fixtures\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||
|
||||
class TestType extends AbstractType
|
||||
{
|
||||
@ -21,23 +22,27 @@ class TestType extends AbstractType
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('a', null, array('description' => 'A nice description'));
|
||||
$builder->add('b');
|
||||
$builder->add($builder->create('c', 'checkbox'));
|
||||
$builder
|
||||
->add('a', null, array('description' => 'A nice description'))
|
||||
->add('b')
|
||||
->add($builder->create('c', 'checkbox'))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefaultOptions()
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
return array(
|
||||
'data_class' => 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\Test',
|
||||
);
|
||||
$resolver->setDefaults(array(
|
||||
'data_class' => 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\Test',
|
||||
));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return '';
|
||||
return 'test_type';
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user