I've actually a problem with SonataAdminBundle
.
I have a file admin.yml:
sonata.admin.Produit:
class: Kayser\PlatformBundle\Admin\ProductionAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Produits", label: "Les Pains & Viennoiseries" }
arguments:
- ~
- Kayser\PlatformBundle\Entity\Product
- ~
calls:
- [ setTranslationDomain, [KayserPlatformBundle]]
sonata.admin.Produit:
class: Kayser\PlatformBundle\Admin\ProductionAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Produits", label: "Les Pains & Viennoiseries" }
arguments:
- ~
- Kayser\PlatformBundle\Entity\ProductImage
- ~
calls:
- [ setTranslationDomain, [KayserPlatformBundle]]`
and my productionAdmin.php:
class ProductionAdmin extends Admin
{
// Fields to be shown on create/edit forms
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('description', 'text', array('label' => 'Description'))
->add('name')
->add('url', 'entity', array(
'class' => 'KayserPlatformBundle:ProductImage',
'property' => 'name',
'multiple' => true))
;
}
// Fields to be shown on filter forms
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('name')
->add('description')
->add('url', 'entity', array(
'class' => 'KayserPlatformBundle:ProductImage',
'property' => 'name',
'multiple' => true))
;
}
// Fields to be shown on lists
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('name')
->add('description')
->add('url', 'entity', array(
'class' => 'KayserPlatformBundle:ProductImage',
'property' => 'name',
'multiple' => true))
;
}
}
and 2 entity Product.php
and ProductImage.php
(they have no problem).
So how to call my second entity with property ? :)
To get a property of another entity in your admin file, I use something like this:
->add(
'productImage',
'entity',
array(
'label' => 'Url',
'class' => 'path/to/ProductImage',
'property' => 'url',
)
)
This is what the docs give for example:
<?php
namespace Acme\DemoBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
class PostAdmin extends Admin
{
// Fields to be shown on create/edit forms
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('title', 'text', array('label' => 'Post Title'))
->add('author', 'entity', array('class' => 'Acme\DemoBundle\Entity\User'))
->add('body') //if no type is specified, SonataAdminBundle tries to guess it
;
}
More info in the docs