I would like to use Doctrine’s preflush features to automatically set the value of form elements based on the values of other elements. The preflush statements in my ZF2 entity might look like this:
/**
* set eventEndDate = eventStartDate for single-day events on pre flush.
*
* @ORM\PreFlush
* @return void
*/
public function onPreFlush(PreFlushEventArgs $args)
{
$currentEventType = $this->getEventType();
if ($currentEventType=='meeting') {
$this->eventEndDate = $this->getEventStartDate();
}
}
My challenge is that I don’t have a getEventType()
getter because eventType is a discriminator column in my inheritance mapping. How can a preflush function in an entity evaluate a discriminator value from within the entity?
You can use instanceof
php operator to check object's class. Like that:
if ($this instanceof MeetingEntityClass) {
//...
}