|
5 | 5 | namespace Shopsys\FrameworkBundle\Component\CKEditor; |
6 | 6 |
|
7 | 7 | use FOS\CKEditorBundle\Renderer\CKEditorRendererInterface; |
| 8 | +use Symfony\Component\HttpFoundation\RequestStack; |
8 | 9 |
|
9 | 10 | class CKEditorRendererDecorator implements CKEditorRendererInterface |
10 | 11 | { |
11 | 12 | /** |
12 | 13 | * @param \FOS\CKEditorBundle\Renderer\CKEditorRendererInterface $baseCkEditorRenderer |
| 14 | + * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack |
13 | 15 | */ |
14 | | - public function __construct(protected readonly CKEditorRendererInterface $baseCkEditorRenderer) |
15 | | - { |
| 16 | + public function __construct( |
| 17 | + protected readonly CKEditorRendererInterface $baseCkEditorRenderer, |
| 18 | + protected readonly RequestStack $requestStack, |
| 19 | + ) { |
16 | 20 | } |
17 | 21 |
|
18 | 22 | /** |
@@ -41,6 +45,8 @@ public function renderJsPath(string $jsPath): string |
41 | 45 | */ |
42 | 46 | public function renderWidget(string $id, array $config, array $options = []): string |
43 | 47 | { |
| 48 | + $config['language'] = $this->getRequestLanguage() ?? $config['language']; |
| 49 | + |
44 | 50 | return sprintf( |
45 | 51 | '$("#%s-preview").click(function() { |
46 | 52 | %s |
@@ -104,4 +110,18 @@ public function renderTemplate(string $name, array $template): string |
104 | 110 | { |
105 | 111 | return $this->baseCkEditorRenderer->renderTemplate($name, $template); |
106 | 112 | } |
| 113 | + |
| 114 | + /** |
| 115 | + * @return string|null |
| 116 | + */ |
| 117 | + protected function getRequestLanguage(): ?string |
| 118 | + { |
| 119 | + $request = $this->requestStack->getCurrentRequest(); |
| 120 | + |
| 121 | + if ($request !== null && $request->getLocale() !== '') { |
| 122 | + return $request->getLocale(); |
| 123 | + } |
| 124 | + |
| 125 | + return null; |
| 126 | + } |
107 | 127 | } |
0 commit comments