1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace App\Controller\Admin; |
6
|
|
|
|
7
|
|
|
use App\Form\Type\FilterSettingsType; |
8
|
|
|
use App\Form\Type\SettingsType; |
9
|
|
|
use App\Repository\SettingsRepository; |
10
|
|
|
use App\Service\Admin\SettingsService; |
11
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
12
|
|
|
use Symfony\Component\HttpFoundation\Request; |
13
|
|
|
use Symfony\Component\HttpFoundation\Response; |
14
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
15
|
|
|
|
16
|
|
|
final class SettingsController extends AbstractController |
17
|
|
|
{ |
18
|
|
|
private SettingsRepository $repository; |
19
|
|
|
private SettingsService $service; |
20
|
|
|
|
21
|
|
|
public function __construct(SettingsRepository $repository, SettingsService $service) |
22
|
|
|
{ |
23
|
|
|
$this->repository = $repository; |
24
|
|
|
$this->service = $service; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @Route("/admin/settings", name="admin_settings") |
29
|
|
|
*/ |
30
|
|
|
public function settings(Request $request): Response |
31
|
|
|
{ |
32
|
|
|
$settings = $this->repository->findAllAsArray(); |
33
|
|
|
|
34
|
|
|
$form = $this->createForm(SettingsType::class, $settings); |
35
|
|
|
$form->handleRequest($request); |
36
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
37
|
|
|
$this->service->updateSettings($form->getNormData()); |
38
|
|
|
|
39
|
|
|
return $this->redirectToRoute('admin_settings'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return $this->render('admin/settings/settings.html.twig', [ |
43
|
|
|
'site' => $settings, |
44
|
|
|
'form' => $form->createView(), |
45
|
|
|
]); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @Route("/admin/settings/header", name="admin_header_settings") |
50
|
|
|
*/ |
51
|
|
|
public function changeHeaderImage(Request $request): Response |
52
|
|
|
{ |
53
|
|
|
$settings = $this->repository->findAllAsArray(); |
54
|
|
|
|
55
|
|
|
$form = $this->createForm(FilterSettingsType::class, $settings); |
56
|
|
|
$form->handleRequest($request); |
57
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
58
|
|
|
$this->service->updateSettings($form->getNormData()); |
59
|
|
|
|
60
|
|
|
return $this->redirectToRoute('admin_header_settings'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return $this->render('admin/settings/header_settings.html.twig', [ |
64
|
|
|
'site' => $settings, |
65
|
|
|
'header_image' => $settings['header_image'], |
66
|
|
|
'logo_image' => $settings['logo_image'], |
67
|
|
|
'form' => $form->createView(), |
68
|
|
|
]); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @Route("/admin/setting/delete_header_image", methods={"POST"}, name="admin_setting_delete_header_image") |
73
|
|
|
*/ |
74
|
|
|
public function deleteHeaderImage(Request $request): Response |
75
|
|
|
{ |
76
|
|
|
// Reset a header image to the default image. |
77
|
|
|
$this->service->resetImage('header_image', $request); |
78
|
|
|
|
79
|
|
|
return $this->redirectToRoute('admin_header_settings'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @Route("/admin/setting/delete_logo_image", methods={"POST"}, name="admin_setting_delete_logo_image") |
84
|
|
|
*/ |
85
|
|
|
public function deleteLogoImage(Request $request): Response |
86
|
|
|
{ |
87
|
|
|
// Reset a header image to the default image. |
88
|
|
|
$this->service->resetImage('logo_image', $request); |
89
|
|
|
|
90
|
|
|
return $this->redirectToRoute('admin_header_settings'); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|