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

前端 未结 6 1049
没有蜡笔的小新
没有蜡笔的小新 2021-02-12 19:46

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->g

6条回答
  •  广开言路
    2021-02-12 20:04

    In sonata admin from version 3.x

      if ($this->isCurrentRoute('create')) {
        // CREATE
      }
      else {
        // EDIT
      }
    

    In sonata admin before version 3.x use:

      $subject = $this->getSubject();
      if ($subject->isNew()) { 
        // CREATE
      }
      else {
        // EDIT
      }
    

提交回复
热议问题