src/UserInterface/BackOffice/EventSubscriber/CustomerSubscriber.php line 19
<?php
declare(strict_types=1);
namespace App\UserInterface\BackOffice\EventSubscriber;
use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CustomerSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
BeforeEntityPersistedEvent::class => ['setCustomerInterlocutorForeignKey'],
];
}
public function setCustomerInterlocutorForeignKey(BeforeEntityPersistedEvent $event)
{
$entity = $event->getEntityInstance();
if (\Customer::class !== get_class($entity)) {
return;
}
foreach ($entity->getInterlocutors() as $interlocutor) {
$interlocutor->setCustomer($entity);
}
}
}