简体   繁体   中英

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!

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

protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
        ->addIdentifier('id', null, ['route' => ['name' => 'show']])
    ;
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM