Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to determine current action (create or edit) in Sonata\AdminBundle\Admin\Admin::configureFormFields()?

I'd like to create different fields configuration for create and edit actions in Sonata Admin Bundle.

Is there any way to determine it except checking $this->getSubject()->getId() in Sonata\AdminBundle\Admin\Admin::configureFormFields()?

like image 575
Max Romanovsky Avatar asked Jul 24 '13 12:07

Max Romanovsky


2 Answers

You can also do this:

protected function configureFormFields(FormMapper $formMapper) {
  if ($this->isCurrentRoute('create')) {
    // CREATE
  }
  else {
    // EDIT
  }
}
like image 92
Picoss Avatar answered Sep 22 '22 11:09

Picoss


with:

if($this->getRequest()->get($this->getIdParameter()) == null){
   // create
} else {
   // edit
}
like image 34
Roberto Avatar answered Sep 23 '22 11:09

Roberto