Compare data after form request , embedded forms

588 Views Asked by At

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?

1

There are 1 best solutions below

0
On

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);

        }
    }
}