1

I have a multiple embedded Form.

My first form holds a collection of Articles:

$builder->add('purchaseOrders', 'collection', array('type' => new AmountOrderArticleType()));

And this form holds a collection of Subarticles:

$builder->add('articleOrderReferences', 'collection', array('type' => new AmountOrderSubArticleType()));

And in this Subarticles i want to edit the amount:

$builder->add('amount');

My goal is to check if the amount has changed in the form and to set a changed value in my entity from 0 to 1 for this amount.

What is the best way to do that?

Edit: I use a preUpdate Eventlistener now:

  public function preUpdate(LifecycleEventArgs $eventArgs)
{   
    $entity = $eventArgs->getEntity();
    $entityManager = $eventArgs->getEntityManager();

    if ($entity instanceof AOSupplierReference) {
            if ($eventArgs->hasChangedField('amount') && $eventArgs->getNewValue('amount') > 0) {
//              $eventArgs->setConfirmed(0);
                $eventArgs->setNewValue('confirmed', 0);
            }
        }
    }

but know i get this error message: Field "confirmed" is not a valid field of the entity "Acme\AppBundle\Entity\AOSupplierReference" in PreUpdateEventArgs. So how can i get access to the confirmed field and set it to false?

ChrisS
  • 736
  • 2
  • 8
  • 21
  • Have a look at [this answer](http://stackoverflow.com/questions/10800178/how-to-check-if-entity-is-changed-in-doctrine-2) please.. You can identify changed entities using a doctrine listener/subscriber. – Nicolai Fröhlich Jul 17 '13 at 11:46
  • thanks for your link, i edited my question now, how can i get access to the confirmed field, which is in the same entity, but not used in the form – ChrisS Jul 17 '13 at 17:27

1 Answers1

1

Alright, fixed it with the Eventlistener, thanks to nifr for the hint.

public function preUpdate(LifecycleEventArgs $eventArgs)
{   
    $entity = $eventArgs->getEntity();
    $em = $eventArgs->getEntityManager();

    if ($entity instanceof AOSupplierReference) {
        if ($eventArgs->hasChangedField('amount')) {

            $entity->setConfirmed(false);

        }
    }
}
ChrisS
  • 736
  • 2
  • 8
  • 21