Skip to content

Commit

Permalink
feat: Made Gravatar optional with roadiz_core.useGravatar config option
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed May 14, 2024
1 parent 9c9b8d9 commit 711676f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ services:
$recaptchaPublicKey: '%roadiz_core.medias.recaptcha_public_key%'
$recaptchaPrivateKey: '%roadiz_core.medias.recaptcha_private_key%'
$webResponseClass: '%roadiz_core.web_response_class%'
$useGravatar: '%roadiz_core.use_gravatar%'

RZ\Roadiz\CoreBundle\:
resource: '../src/'
Expand Down
3 changes: 3 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public function getConfigTreeBuilder(): TreeBuilder
->booleanNode('hideRoadizVersion')
->defaultValue(false)
->end()
->booleanNode('useGravatar')
->defaultTrue()
->end()
->scalarNode('documentsLibDir')->defaultValue(
'vendor/roadiz/documents/src'
)->info('Relative path to Roadiz Documents lib sources from project directory.')->end()
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/RoadizCoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function load(array $configs, ContainerBuilder $container): void

$container->setParameter('roadiz_core.app_namespace', $config['appNamespace']);
$container->setParameter('roadiz_core.app_version', $config['appVersion']);
$container->setParameter('roadiz_core.use_gravatar', $config['useGravatar']);
$container->setParameter('roadiz_core.health_check_token', $config['healthCheckToken']);
$container->setParameter('roadiz_core.inheritance_type', $config['inheritance']['type']);
$container->setParameter('roadiz_core.max_versions_showed', $config['maxVersionsShowed']);
Expand Down
32 changes: 10 additions & 22 deletions src/Doctrine/EventSubscriber/UserLifeCycleSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,13 @@

final class UserLifeCycleSubscriber implements EventSubscriber
{
private UserViewer $userViewer;
private EventDispatcherInterface $dispatcher;
private PasswordHasherFactoryInterface $passwordHasherFactory;
private LoggerInterface $logger;

/**
* @param UserViewer $userViewer
* @param EventDispatcherInterface $dispatcher
* @param PasswordHasherFactoryInterface $passwordHasherFactory
* @param LoggerInterface $logger
*/
public function __construct(
UserViewer $userViewer,
EventDispatcherInterface $dispatcher,
PasswordHasherFactoryInterface $passwordHasherFactory,
LoggerInterface $logger
private readonly UserViewer $userViewer,
private readonly EventDispatcherInterface $dispatcher,
private readonly PasswordHasherFactoryInterface $passwordHasherFactory,
private readonly LoggerInterface $logger,
private readonly bool $useGravatar
) {
$this->userViewer = $userViewer;
$this->dispatcher = $dispatcher;
$this->logger = $logger;
$this->passwordHasherFactory = $passwordHasherFactory;
}

/**
Expand Down Expand Up @@ -94,9 +80,11 @@ public function preUpdate(PreUpdateEventArgs $event): void
$user->setPictureUrl($url);
} catch (\Exception $e) {
$user->setFacebookName('');
$user->setPictureUrl($user->getGravatarUrl());
if ($this->useGravatar) {
$user->setPictureUrl($user->getGravatarUrl());
}
}
} else {
} elseif ($this->useGravatar) {
$user->setPictureUrl($user->getGravatarUrl());
}
}
Expand Down Expand Up @@ -201,7 +189,7 @@ public function prePersist(LifecycleEventArgs $event): void
/*
* Force a Gravatar image if not defined
*/
if (empty($user->getPictureUrl())) {
if (empty($user->getPictureUrl()) && $this->useGravatar) {
$user->setPictureUrl($user->getGravatarUrl());
}
}
Expand Down

0 comments on commit 711676f

Please sign in to comment.