Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonata Admin Change Edit link by Show link

I'm using SonataAdminBundle and I'm triying to change the edit link of and entity by the show link.

I want to do this because I need the entity couldn't be modified but I want you can show the entity by clicking in the Identifier field of the list page.

I need to show the entity by clicking in the Identifier, and not using the show action buttom.

So I tried in the ClassAdmin:

protected function configureRoutes(RouteCollection $collection){

  $collection->add('edit',  $this->getRouterIdParameter().'/show');

}

Despite the url is generated with the show correctly, the Identifier in the list page redirect to the edit page. Really, wathever I change in the edit link doesn't take efect and always redirect to the edit page.

Thansk a lot!

like image 829
Angel Avatar asked May 23 '13 14:05

Angel


2 Answers

You can give the default action like this (in your admin classes):

protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
        ->addIdentifier('id', null, ['route' => ['name' => 'show']])
    ;
}
like image 171
shinework Avatar answered Sep 30 '22 19:09

shinework


Finally, it works by:

protected function configureRoutes(RouteCollection $collection){

    $collection->remove('edit');
    $collection->add('edit',  $this->getRouterIdParameter().'/show');

}

I don't know why I have to remove the edit link first... but it works.

like image 24
Angel Avatar answered Sep 30 '22 20:09

Angel