I tried the last days for SonataMedia to work with Symfony 2.0.16 ... without success. It looks like a Google search looks like many people are not using this package or there is no tutorial or practical guide that I don’t know about, because I don’t get much information about the error messages that I have.
Anyway, my last attempt gave the following error message:
The current field `path` is not linked to an admin. Please create one for the target entity : ``
"path" is a field used to save the file path of a (relative) file.
AttachmentAdmin.php
<?php
class AttachmentAdmin extends Admin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add(
'path',
'sonata_type_collection',
array(
'required' => true
),
array(
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'position',
'targetEntity' => 'Application\Sonata\MediaBundle\Entity\GalleryHasMedia',
'link_parameters' => array(
'context' => 'attachment'
)
)
)
->add('notes', 'textarea', array('required' => false))
;
}
}
attachment.php
<?php
class Attachment
{
protected $path;
public function setPath($path)
{
$this->path = $path;
foreach ($path as $ent) {
$ent->setAttachment($this);
}
}
public function getPath()
{
return $this->path;
}
public function addPath(\Application\Sonata\MediaBundle\Entity\GalleryHasMedia $path)
{
$this->path[] = $path;
}
}
GalleryHasMedia.php
<?php
class GalleryHasMedia extends BaseGalleryHasMedia
{
protected $id;
private $attachment;
public function getId()
{
return $this->id;
}
public function setAttachment(\Mercury\CargoRecognitionBundle\Entity\Attachment $attachment = null)
{
$this->attachment = $attachment;
return $this;
}
public function getAttachment()
{
return $this->attachment;
}
}
services.yml
mercury.cargo_recognition.admin.attachment:
class: Mercury\CargoRecognitionBundle\Admin\AttachmentAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: General, label: Attachments }
arguments: [ null, Mercury\CargoRecognitionBundle\Entity\Attachment, "MercuryCargoRecognitionBundle:AttachmentAdmin" ]
Thanks for any info!