mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
start of entity listener for person name capitalization
This commit is contained in:
parent
ddbd6a9f23
commit
af4cf55046
@ -0,0 +1,8 @@
|
||||
services:
|
||||
Chill\PersonBundle\EventListener\:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
tags:
|
||||
- name: "doctrine.orm.entity_listener"
|
||||
event: "prePersist"
|
||||
entity: 'Chill\PersonBundle\Entity\Person'
|
@ -268,7 +268,7 @@ final class PersonController extends AbstractController
|
||||
) {
|
||||
$this->em->persist($person);
|
||||
|
||||
$this->em->flush();
|
||||
// $this->em->flush();
|
||||
$this->lastPostDataReset();
|
||||
|
||||
if ($form->get('createPeriod')->isClicked()) {
|
||||
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\EventListener;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\Persistence\Event\LifecycleEventArgs;
|
||||
|
||||
class PersonCreateEvent
|
||||
{
|
||||
public EntityManager $em;
|
||||
|
||||
public function __construct(EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function onPrePersist(LifecycleEventArgs $event): void
|
||||
{
|
||||
$person = $event->getObject();
|
||||
|
||||
if ($person instanceof Person){
|
||||
$firstnameCaps = ucfirst(strtolower($person->getFirstName()));
|
||||
$person->setFirstName($firstnameCaps);
|
||||
|
||||
$lastnameCaps = strtoupper($person->getLastName());
|
||||
$person->setLastName($lastnameCaps);
|
||||
|
||||
dump($person);
|
||||
// $this->em->persist($person);
|
||||
// $this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user