I am having a hard time wrapping my head around this, I have started a project based on Symfony 4 + PHPCR + CMF + Sonata admin, I do not have much experience with Symfony and I suppose I should have started with something simpler, but hey...
Anyways I have gone through loops and hoops to get this working and I have, but sometimes I get really stuck on somthing that I'm not sure is an issue or just my incompetence.
This is one of those times, I have made the media bundle work, except for one thing (well two things, but mainly this one thing)... I uploaded some media files (images) and then I tried to add them to Gallery. But upon clicking the Add new
button, which renders html for assigning media, I am getting the following error from the ajax request:
Argument 1 passed to Sonata\AdminBundle\Form\DataTransformer\ModelToIdTransformer::__construct() must implement interface Sonata\AdminBundle\Model\ModelManagerInterface, null given, called in /var/www/html/vendor/sonata-project/admin-bundle/src/Form/Type/ModelListType.php on line 51
Now I have gone through the stack trace (yay abstraction) and through some source code and came up with the following:
ModelToldTransformer expects first argument to be of type
ModelManagerInterface
(see at github)The argument is passed from
doctrine-phpcr-admin-bundle
(see at github)The field is built without the
model_manager
option (see at github)
Symfony docs about form types say:
model_manager
defaults to null, but is actually calculated from the linked Admin class.
You usually should not need to set this manually.
So I am thinking that the Admin class is not linked to the PHPCR class?
So then I tried linking this manually (I found a similiar example in another bundle) in .../media-bundle/src/Admin/GalleryHasMediaAdmin.php
Here is a gist revision of what changed
Once that is fixed, the call does not throw an exception, but it also does not render any fields, just the Add new
button again and nothing else.
I would really welcome any pointers as to what to do next, I am pretty sure that defining model_manager
is not the right way to go (and it neither fixes the whole damn thing), but because of the level of abstraction, it is really hard to dig into it and find what's wrong.
This is the list of dependencies that I currently have installed.
And this is sonata configuration merged into a single file.
I would love to provide even more info, but I am not sure what else would be relevant