My problem is the following. I am using Sonata Admin with Symfony. In the Admin section, when I try to create an entity, nothing appears when I click on the add button (spelled "Ajouter"):
I get the following error: Call to a member function getName() on a non-object
in the chrome console
Here's how my entities hierarchy is, I have three objects that are linked together in the following way:
Video ---OneToOne--> String ---OneToMany--> LocalizedString
Simply, I have one video that will have a title and this title will be translated. Here are my entities:
LocalizedString
OSC\UtilsBundle\Entity\LocalizedString: type: entity table: null repositoryClass: OSC\UtilsBundle\Entity\LocalizedStringRepository id: id: type: integer id: true generator: strategy: AUTO fields: locale: type: string length: '20' content: type: string length: 255 manyToOne: parent: targetEntity: String mappedBy: localizedObjects lifecycleCallbacks: { }
String
OSC\UtilsBundle\Entity\String: type: entity table: null repositoryClass: OSC\UtilsBundle\Entity\StringRepository id: id: type: integer id: true generator: strategy: AUTO oneToMany: localizedObjects: targetEntity: LocalizedString mappedBy: parent cascade: ["persist", "remove"] lifecycleCallbacks: { }
Video
OSC\MySportBundle\Entity\Video: type: entity table: null repositoryClass: OSC\MySportBundle\Entity\VideoRepository id: id: type: integer id: true generator: strategy: AUTO oneToOne: title: targetEntity: OSC\UtilsBundle\Entity\String cascade: ["persist", "remove"] lifecycleCallbacks: { }
So, I did this structure to facilitate the editing in SonataAdmin. If, through the admin dashboard, I want to edit a String, I can easily edit a string and translate it in many languages (this already works).
However, when I try to do that in the video admin, it seems that I cannot do inline editing (clicking the add button does not work) of the String object.
Here's the relevant code in video admin class:
$formMapper ->add('title', 'sonata_type_admin', array('delete' => false, 'btn_add' =>false), array( 'edit' => 'inline', 'inline' => 'table', ));
From what I have found, it looks like two imbricated forms are not possible ? Is there a way to circumvent that restriction ? Or maybe it is my design that is not too good ?
Edit1: It looks like there is a patch coming on github: https://github.com/sonata-project/SonataAdminBundle/pull/1971#issuecomment-58023124
If anyone knows how I can use it I would appreciate.
In your code you are using delete
which is not a valid option. Maybe you can try 'btn_delete' => false
Check the documentation for all the valid options here.
If this not working, maybe sonata_type_collection
is the solution to your problem. Ensure that you are using the by_reference
option the correct way depending on your relation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With