Sonataadminbundle: Remove link on relation ManyToOne OneToMany

Created on 7 Oct 2014  路  10Comments  路  Source: sonata-project/SonataAdminBundle

I have an entity with a relation OneToMany (and another with ManyToOne.. yep)

When I display the list of my datas in my admin (show list), I can see a link on the field with a relation.

This link is for edit the data linked (url like /user/2/edit). I don't want it, how can I remove this link ?

pending author stale

Most helpful comment

I think it not the best way to do but you can use this trick for a field one-to-many :
$listMapper->add('collection', null, ['route' => ['name' => '']])

All 10 comments

Maybe using route parameter: http://sonata-project.org/bundles/admin/master/doc/reference/routing.html#changing-the-default-route-in-a-list-action try to set it to null. Or you can remove the permission in the user.

One year after, the easiest solution:
Instead of:

protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
      ->add('user') // add a edit link to the related user entity
    ;
}

Just do:

protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
      ->add('user', 'text') // 'text' type just display User toString method without link
    ;
}

@TheKassaK did this help?

If yes, please close this issue, thank you!

Tried the solution provided by @cassianotartari with null, false etc., didn't work out.
Solution by @fsanter works just fine.

Please close @TheKassaK !

@webdevilopers would you create a PR for the docs? i think many people could use this trick

Sure. Maybe @pulzarraider or @rande can confirm that this approach is best / only practice for this issue?

Hi Guys
The same but in configureShowFields ?
I have in fiel one-to-many

$showMapper
->add('segments', null, array('label' => 'Segments in payroll'))
;
I tried with: 'string', 'text', but it does not work

Same Problem with @ederrafo

Even in my ListView it didn't work. @fsanter

I think it not the best way to do but you can use this trick for a field one-to-many :
$listMapper->add('collection', null, ['route' => ['name' => '']])

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Was this page helpful?
0 / 5 - 0 ratings