eventlistener added to capitalize names correctly

This commit is contained in:
Julie Lenaerts 2022-03-14 11:49:01 +01:00
parent 09e6872724
commit 96e38a8a6d
3 changed files with 41 additions and 0 deletions

View File

@ -46,6 +46,7 @@ class ChillThirdPartyExtension extends Extension implements PrependExtensionInte
$loader->load('services/fixtures.yaml');
$loader->load('services/serializer.yaml');
$loader->load('services/repository.yaml');
$loader->load('services/doctrineEventListener.yaml');
}
public function prepend(ContainerBuilder $container)

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\ThirdPartyBundle\EventListener;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use const MB_CASE_TITLE;
class ThirdPartyEventListener
{
public function prePersistThirdParty(ThirdParty $thirdparty): void
{
if ($thirdparty->getKind() !== 'company') {
$firstnameCaps = mb_convert_case(mb_strtolower($thirdparty->getFirstname()), MB_CASE_TITLE, 'UTF-8');
$firstnameCaps = ucwords(strtolower($firstnameCaps), " \t\r\n\f\v'-");
$thirdparty->setFirstName($firstnameCaps);
$lastnameCaps = mb_strtoupper($thirdparty->getName(), 'UTF-8');
$thirdparty->setName($lastnameCaps);
}
}
}

View File

@ -0,0 +1,9 @@
services:
Chill\ThirdPartyBundle\EventListener\ThirdPartyEventListener:
autoconfigure: true
tags:
-
name: 'doctrine.orm.entity_listener'
event: 'prePersist'
entity: 'Chill\ThirdPartyBundle\Entity\ThirdParty'
method: 'prePersistThirdParty'