简体   繁体   中英

How to remove routes depending the object Sonata Admin

I would like to remove the delete route for certain objects (which are linked to others...).

Is there a way to remove Routes in the configureRoutes method depending on the edited object (for example the id)?

Or is there a way to do it in the configureFormFields method?

EDIT: This is a very old answer, so it may or may not work in your case

To get the current object inside XXXAdmin class use:

$this->getSubject();

protected function configureFormFields(FormMapper $formMapper) {
  $product = $this->getSubject();

  if ($product->getId()) { // editing
    //
  }
  //...
}

public function configureRoutes(\Sonata\AdminBundle\Route\RouteCollection $collection)  {
  $product = $this->getSubject();

  if ($product->getId()) { // editing
    $collection->remove('route');
  }

}

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