Hi all!
I want in CarAdmin class choose specific kind engine (engineKind) and fill
fields specific Engine (GasEngine or PetrolEngine).
How to do it right?
Thanks
These are the entity classes:
/**
* @ORM\Entity
*/
class Car {
...
/**
* @DoctrineAssert\Enum(entity="AppBundle\DBAL\Types\EngineType")
*/
protected $engineKind;
/**
* @ORM\OneToOne(targetEntity="AppBundle\Entity\Engine",
mappedBy="car", cascade={"persist","refresh","remove"})
*/
protected $engine;
...
}
/**
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="entity", type="string")
* @ORM\DiscriminatorMap( {
* "gas" = "AppBundle\Entity\GasEngine",
* "petrol" = "AppBundle\Entity\PetrolEngine"
* } )
*/
class Engine {
...
/**
* @ORM\OneToOne(targetEntity="\AppBundle\Entity\Car",
inversedBy="engine")
*/
protected $car;
... // other common members
}
/**
* @ORM\Entity
*/
class GasEngine extends Engine {
... // unique members
}
/**
* @ORM\Entity
*/
class PetrolEngine extends Engine {
... // unique members
}
These are the Admin classes:
class CarAdmin extends Admin {
...
protected function configureFormFields(FormMapper $formMapper) {
...
$formMapper
->add('engineKind')
->add('engine', 'sonata_type_admin', array('required' => false,))
->end();
...
}
...
}
class EngineAdmin extends Admin {
...
protected function configureFormFields(FormMapper $formMapper) {
$form->add('name');
$subject = $this->getSubject();
if ($subject instanceof \AppBundle\Entity\GasEngine) {
$formMapper->add('member_gas_1');
} elseif ($subject instanceof \AppBundle\Entity\PatrolEngine) {
$formMapper->add('member_patrol_1');
}
}
...
}
--
You received this message because you are subscribed to the Google Groups
"sonata-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sonata-users.
For more options, visit https://groups.google.com/d/optout.