I\'m having problems creating my form for creating a course. This is a part of my database scheme for which I\'m trying to create a form:
So which I\'m trying t
This error occurs because you have more than two level of nested collection forms, and it's currently not yet supported in any release of sonata-admin.
From @rande (owner) and sonata maintainers at issues #262, #1228, #1327 and #1971 :
This is still not supported for now ....
You can also look at this old PR #1971 which should solve the problem for some use cases only.
The solution I propose you is to implement the fix provided by the last opened PR #2985.
Because the PR is not merged, you need to tell composer to load it rather than the current (not-working as expected) version. (see composer and VCS).
Hope the PR is merged soon.
Until it is, feel free to fix your problem at the moment by using it directly, as several people do.
UPDATE
The Pull Request #3553 has been recently merged and fix the problem of the nested collections at > 2 levels (nested in nested).
To get the fixed release, you must use the dev-master
tag of the bundle (at least from the commit 926f159 representing the merge of the PR).
I tried it and it works well with the following requirement:
// composer.json
"require": {
"sonata-project/admin-bundle": "^2.4@dev",
...
},
I hope you can easily upgrade the bundle in order to get the fix.
Update2
Apparently, your composer doesn't take the last changes of the branch.
The fix provided by the PR #2739 has been merged 6 days ago.
To fix this last one (hope), you need to change a very short code block in the AddDepencyCallsCompilerPass
located in vendor/sonata-project/admin-bundle/DependencyInjection/Compiler/AddDependencyCallsCompilerPass
.
At line 95, replace this line :
$groupDefaults[$resolvedGroupName]['items'][] = $id;
To those ones:
$groupDefaults[$resolvedGroupName]['items'][] = array(
'admin' => $id,
'label' => !empty($attributes['label']) ? $attributes['label'] : '',
'route' => '',
'route_params' => array(),
);
Like it's done by the PR (it's the only needed change to make it working).
I would make the fix manually because it's very new, and after some days/weeks, run the following commands:
composer clear-cache
and composer update sonata-project/admin-bundle
You should try it now before adding the fix manually, maybe the changes will be added.
Also, you can use the link about composer and VCS I given at the begin of my answer and require the fix directly. It's at your own appreciation because of it's a solution at the moment.
And last, be patient, the fixes will be merged in stable releases soon.
public function getChildFormBuilder(FormBuilder $formBuilder, $elementId)
{
foreach (new FormBuilderIterator($formBuilder) as $name => $formBuilder) {
if ($name == $elementId) {
return $formBuilder;
}
}
return;
}
Dumping the name and element id within the loop won't accomplish anything. Your application obviously crashes when there is nothing to iterate - it then walks through the loop, exits and goes to the last line where NULL
is returned.
I suggest you dump the element id just after the loop, like the following. The use of debug_backtrace might also help:
public function getChildFormBuilder(FormBuilder $formBuilder, $elementId)
{
foreach (new FormBuilderIterator($formBuilder) as $name => $formBuilder) {
if ($name == $elementId) {
return $formBuilder;
}
}
var_dump(__METHOD__);
var_dump($elementId);
var_dump(debug_backtrace());
return;
}