Environment
Symfony 3.4.4 + FOSBundleUser + Sonata Admin + Media Bundle
Subject
I have installed Media Bundle. I have configured it following the steps indicated in the Official documentation.
I have created a field in my entity Products to attach a catalog in PDF format.
I have added in Sonata Adminel field mapping.
When viewing the list of products in Sonata Admin, there is no problem, but when enter to edit or create a new product, give this error:
Impossible to invoke a method ("id") on a null variable.
This is the definition of my field to attach a PDF in my entity
/**
* @var Media
*
* @ORM\ManyToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Media")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="fileCatalog_id", referencedColumnName="id")
* })
*/
private $fileCatalog;
This is the mapping of the field in the Sonata Admin form
->add('fileCatalog', 'sonata_type_model_list', array(
'required' => false,
'label'=>'Imagen EspaƱol'
), array(
'link_parameters' => array(
'context' => 'default',
'provider' => 'sonata.media.provider.file',
'empty_on_new' => true,
)
)
)