How to check if Subject is New resp. action is create or edit in Sonata Admin

0 Flares Twitter 0 Facebook 0 LinkedIn 0 0 Flares ×

In your Admin Class:

In your Twig Template:

Source: https://github.com/sonata-project/SonataAdminBundle/blob/master/Resources/views/CRUD/base_edit_form.html.twig#L4

 

Backlinks:

Web Deviloper

  • Pingback: How to check if Subject is New resp. action is ...()

  • Dorian Villet

    This code is not safe, as $this->getSubject() might return false, and $this->id() will throw a RunTimeException(‘Invalid argument, object or null required’);. You’d rather do something like : if ( $this->getSubject() && $this->id($this->getSubject()) ) { … }