|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Zikula package. |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright Zikula - https://ziku.la/ |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Zikula\UsersBundle\Controller; |
|
15
|
|
|
|
|
16
|
|
|
use Locale; |
|
17
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
19
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
20
|
|
|
use Symfony\Component\Intl\Languages; |
|
21
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
22
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
|
23
|
|
|
use Symfony\Component\Security\Http\Attribute\IsGranted; |
|
24
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
|
25
|
|
|
use Zikula\Bundle\CoreBundle\Api\ApiInterface\LocaleApiInterface; |
|
26
|
|
|
use Zikula\UsersBundle\Api\ApiInterface\CurrentUserApiInterface; |
|
|
|
|
|
|
27
|
|
|
use Zikula\UsersBundle\Entity\User; |
|
28
|
|
|
use Zikula\UsersBundle\Event\DeleteUserFormPostCreatedEvent; |
|
|
|
|
|
|
29
|
|
|
use Zikula\UsersBundle\Event\DeleteUserFormPostValidatedEvent; |
|
|
|
|
|
|
30
|
|
|
use Zikula\UsersBundle\Form\Type\ChangeLanguageType; |
|
31
|
|
|
use Zikula\UsersBundle\Helper\DeleteHelper; |
|
32
|
|
|
use Zikula\UsersBundle\Repository\UserRepositoryInterface; |
|
33
|
|
|
use Zikula\UsersBundle\UsersConstant; |
|
34
|
|
|
|
|
35
|
|
|
#[Route('/account')] |
|
36
|
|
|
#[IsGranted('ROLE_USER')] |
|
37
|
|
|
class AccountController extends AbstractController |
|
38
|
|
|
{ |
|
39
|
|
|
public function __construct( |
|
40
|
|
|
private readonly TranslatorInterface $translator, |
|
41
|
|
|
private readonly bool $displayGraphics, |
|
42
|
|
|
private readonly bool $allowSelfDeletion |
|
43
|
|
|
) { |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @throws AccessDeniedException Thrown if the user isn't logged in |
|
48
|
|
|
*/ |
|
49
|
|
|
#[Route('', name: 'zikulausersbundle_account_menu')] |
|
50
|
|
|
public function menu(): Response |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->redirect('/'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @throws AccessDeniedException Thrown if the user isn't logged in |
|
57
|
|
|
*/ |
|
58
|
|
|
#[Route('/change-language', name: 'zikulausersbundle_account_changelanguage')] |
|
59
|
|
|
public function changeLanguage( |
|
60
|
|
|
Request $request, |
|
61
|
|
|
CurrentUserApiInterface $currentUserApi, |
|
62
|
|
|
UserRepositoryInterface $userRepository, |
|
63
|
|
|
LocaleApiInterface $localeApi |
|
64
|
|
|
): Response { |
|
65
|
|
|
if (!$currentUserApi->isLoggedIn()) { |
|
66
|
|
|
throw new AccessDeniedException(); |
|
67
|
|
|
} |
|
68
|
|
|
$form = $this->createForm(ChangeLanguageType::class, [ |
|
69
|
|
|
'locale' => $currentUserApi->get('locale'), |
|
70
|
|
|
]); |
|
71
|
|
|
$form->handleRequest($request); |
|
72
|
|
|
if ($form->isSubmitted()) { |
|
73
|
|
|
$locale = $this->getParameter('locale'); |
|
74
|
|
|
if ($form->get('submit')->isClicked()) { |
|
|
|
|
|
|
75
|
|
|
$data = $form->getData(); |
|
76
|
|
|
$locale = !empty($data['locale']) ? $data['locale'] : $locale; |
|
77
|
|
|
/** @var User $userEntity */ |
|
78
|
|
|
$userEntity = $userRepository->find($currentUserApi->get('uid')); |
|
79
|
|
|
$userEntity->setLocale($locale); |
|
80
|
|
|
$userRepository->persistAndFlush($userEntity); |
|
81
|
|
|
if ($request->hasSession() && ($session = $request->getSession())) { |
|
82
|
|
|
$session->set('_locale', $locale); |
|
83
|
|
|
} |
|
84
|
|
|
Locale::setDefault($locale); |
|
|
|
|
|
|
85
|
|
|
$langText = Languages::getName($locale); |
|
86
|
|
|
$this->addFlash('success', $this->translator->trans('Language changed to %lang%', ['%lang%' => $langText], 'messages', $locale)); |
|
87
|
|
|
} elseif ($form->get('cancel')->isClicked()) { |
|
88
|
|
|
$this->addFlash('status', 'Operation cancelled.'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return $this->redirectToRoute('zikulausersbundle_account_menu', ['_locale' => $locale]); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return $this->render('@ZikulaUsers/Account/changeLanguage.html.twig', [ |
|
95
|
|
|
'form' => $form->createView(), |
|
96
|
|
|
'multilingual' => $localeApi->multilingual(), |
|
97
|
|
|
]); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths