Search code examples
symfonysonata-admin

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()?


Solution

  • You can also do this:

    protected function configureFormFields(FormMapper $formMapper) {
      if ($this->isCurrentRoute('create')) {
        // CREATE
      }
      else {
        // EDIT
      }
    }