mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Add support for nested form types
This commit is contained in:
parent
15a4558277
commit
83c91a3d9d
@ -55,12 +55,22 @@ class FormTypeParser
|
|||||||
if (is_string($type) && class_exists($type)) {
|
if (is_string($type) && class_exists($type)) {
|
||||||
$type = new $type();
|
$type = new $type();
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = $this->formFactory->create($type);
|
$form = $this->formFactory->create($type);
|
||||||
|
|
||||||
|
return $this->parseForm($form);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function parseForm($form, $prefix = null)
|
||||||
|
{
|
||||||
$parameters = array();
|
$parameters = array();
|
||||||
foreach ($form as $name => $child) {
|
foreach ($form as $name => $child) {
|
||||||
$config = $child->getConfig();
|
$config = $child->getConfig();
|
||||||
|
|
||||||
|
if ($prefix) {
|
||||||
|
$name = sprintf('%s[%s]', $prefix, $name);
|
||||||
|
}
|
||||||
|
|
||||||
$bestType = '';
|
$bestType = '';
|
||||||
for ($type = $config->getType(); null !== $type; $type = $type->getParent()) {
|
for ($type = $config->getType(); null !== $type; $type = $type->getParent()) {
|
||||||
if (isset($this->mapTypes[$type->getName()])) {
|
if (isset($this->mapTypes[$type->getName()])) {
|
||||||
@ -68,6 +78,17 @@ class FormTypeParser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('' === $bestType) {
|
||||||
|
if ($type = $config->getType()) {
|
||||||
|
if ($type = $type->getInnerType()) {
|
||||||
|
$subForm = $this->formFactory->create($type);
|
||||||
|
$parameters = array_merge($parameters, $this->parseForm($subForm, $name));
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$parameters[$name] = array(
|
$parameters[$name] = array(
|
||||||
'dataType' => $bestType,
|
'dataType' => $bestType,
|
||||||
'required' => $config->getRequired(),
|
'required' => $config->getRequired(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user