Smashou
Smashou

Reputation: 378

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 ?

Upvotes: 3

Views: 1381

Answers (1)

tttony
tttony

Reputation: 5092

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');
  }

}

Upvotes: 1

Related Questions