AccompanyingPeriodWork: add doctrine event listener to add logged user to referrers collection

This commit is contained in:
nobohan 2022-03-10 10:53:40 +01:00
parent 55a65ee6e9
commit da650fa1f2
2 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,31 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\EventListener;
use Symfony\Component\Security\Core\Security;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
class AccompanyingPeriodWorkEventListener
{
private Security $security;
public function __construct(Security $security)
{
$this->security = $security;
}
public function prePersistAccompanyingPeriodWork(AccompanyingPeriodWork $work): void
{
$work->addReferrer($this->security->getUser());
}
}

View File

@ -12,3 +12,13 @@ services:
event: 'prePersist'
entity: 'Chill\PersonBundle\Entity\PersonAltName'
method: 'prePersistAltName'
Chill\PersonBundle\EventListener\AccompanyingPeriodWorkEventListener:
autoconfigure: true
autowire: true
tags:
-
name: 'doctrine.orm.entity_listener'
event: 'prePersist'
entity: 'Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork'
method: 'prePersistAccompanyingPeriodWork'