In a controller, I define a form which lets the user do some changes on some fields:
$page['community']
is an entity with president
, vicepresident
, secretary
and administrator
properties, among others. Each one associated to a Pro\UserBundle\Entity\User
entity (id):
$form = $this->createFormBuilder($page['community'])
->add('president', 'entity', array(
'label' => "Presidente",
'class' => 'Pro\UserBundle\Entity\User',
'property' => 'fullName',
'choices' => $page['community']->getOwners()
))
->add('vicepresident', 'entity', array(
'label' => "Vicepresidente",
'class' => 'Pro\UserBundle\Entity\User',
'property' => 'fullName',
'choices' => $page['community']->getOwners(),
'required' => false
))
->add('secretary', 'entity', array(
'label' => "Secretario",
'class' => 'Pro\UserBundle\Entity\User',
'property' => 'fullName',
'choices' => $page['community']->getOwners(),
'required' => false
))
->add('administrator', 'entity', array(
'label' => "Administrador",
'class' => 'Pro\UserBundle\Entity\User',
'property' => 'fullName',
'choices' => $page['community']->getMembers(),
'required' => false
))
->getForm();
if ($this->getRequest()->isMethod('post')) {
if ($form->bind($this->getRequest())->isValid()) {
$this->getEntityManager()->flush();
...
This works right. But now I want to fire some events depending on the changed properties. E.g. I want to fire an event when the administrator
property has changed.
I can get the whole new values, but I don't know which of them have changed. I could get those values before the flush and then compare each one with the new values, but maybe there is a simpler way to achieve it. Any idea?