Sonata add a link to the related entity only when you add the entity, and not when you add a property of the entity.
The following example will add a link to Entity2
:
/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
...
->add('Entity2')
...
;
}
Whereas this example will not add a link to the entity2
:
/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
...
->add('Entity2.name')
...
;
}
If you want to display the name
property in the link, you have to add or change the __toString()
method in Entity2
:
class Entity2
{
...
public function __toString()
{
return (string) $this->name;
}
}
Your admin class should be like this:
/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier( 'type.titre' , null, array ( 'label' => 'Type') )
->add('valeur', null, array ( 'label' => 'Valeur' ) )
->add('bioprofile.titre', null, array ( 'label' => 'Bio Profile' ) )
->add( 'exercicesData.entrainement.niveau', null, array( 'label' => 'Niveau' , 'route' => array( 'name' => 'edit') ) )
->add( 'exercicesData.entrainement' , many_to_one, array ( 'label' => 'Entrainement' ) )
->add( 'exercicesData.entrainement.niveau.programme' , null , array ( 'label' => 'Programme' ) )
->add('_action', 'actions', array(
'actions' => array(
'show' => array(),
'edit' => array(),
'delete' => array(),
)
))
;
}
And you should change the following entities:
Entity Entrainement
:
class Entrainement
{
...
public function __toString()
{
return (string) $this->titre;
}
}
Entity Niveau
:
class Niveau
{
...
public function __toString()
{
return (string) $this->titre;
}
}
Entity Programme
:
class Programme
{
...
public function __toString()
{
return (string) $this->titre;
}
}
Hope this helps