Skip to content

Commit 7720f1c

Browse files
Merge pull request #74 from vmalyk/hotfix/missed-translator-in-controller
Added and fixed controller for getting translations
2 parents 64ce8d3 + d9aae6a commit 7720f1c

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/WorkflowGui/Controller/WorkflowController.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use Pimcore\Bundle\CoreBundle\DependencyInjection\Configuration;
2020
use Pimcore\Cache\Symfony\CacheClearer;
21+
use Symfony\Contracts\Translation\TranslatorInterface;
2122
use Pimcore\Controller\Traits\JsonHelperTrait;
2223
use Pimcore\Controller\UserAwareController;
2324
use Pimcore\Model\User;
@@ -42,6 +43,7 @@ public function __construct(
4243
protected ConfigFileResolverInterface $configFileResolver,
4344
protected KernelInterface $kernel,
4445
protected CacheClearer $cacheClearer,
46+
protected TranslatorInterface $translator
4547
) {}
4648

4749
public function listAction(): JsonResponse
@@ -91,7 +93,7 @@ public function cloneAction(Request $request): JsonResponse
9193
if ($workflowByName) {
9294
return $this->json([
9395
'success' => false,
94-
'message' => $this->trans('workflow_gui_workflow_with_name_already_exists'),
96+
'message' => $this->translator->trans('workflow_gui_workflow_with_name_already_exists'),
9597
]);
9698
}
9799

@@ -283,12 +285,12 @@ public function visualizeAction(Request $request): Response
283285
$this->isGrantedOr403();
284286

285287
try {
286-
return new Response($this->container->get('twig')->render(
288+
return $this->render(
287289
'@WorkflowGui/Workflow/visualize.html.twig',
288290
[
289291
'image' => $this->getVisualization($request->get('workflow'), 'svg'),
290292
]
291-
));
293+
);
292294
} catch (\Throwable $e) {
293295
return new Response($e->getMessage());
294296
}
@@ -325,21 +327,21 @@ private function getVisualization($workflow, $format): string
325327
$dot = Console::getExecutable('dot');
326328

327329
if (!$php) {
328-
throw new \InvalidArgumentException($this->trans('workflow_cmd_not_found', ['php']));
330+
throw new \InvalidArgumentException($this->translator->trans('workflow_cmd_not_found', ['php'], 'admin'));
329331
}
330332

331333
if (!$dot) {
332-
throw new \InvalidArgumentException($this->trans('workflow_cmd_not_found', ['dot']));
334+
throw new \InvalidArgumentException($this->translator->trans('workflow_cmd_not_found', ['dot'], 'admin'));
333335
}
334336

335337
$workflowRepository = $this->repository->find($workflow);
336338

337339
if ($workflowRepository === null) {
338-
throw new \InvalidArgumentException($this->trans('workflow_gui_not_found'));
340+
throw new \InvalidArgumentException($this->translator->trans('workflow_gui_not_found', [], 'admin'));
339341
}
340342

341343
if (!$workflowRepository['enabled'] ?? false) {
342-
throw new \InvalidArgumentException($this->trans('workflow_gui_enable_message'));
344+
throw new \InvalidArgumentException($this->translator->trans('workflow_gui_enable_message', [], 'admin'));
343345
}
344346

345347
$cmd = $php.' '.PIMCORE_PROJECT_ROOT.'/bin/console --env="${:arg_environment}" pimcore:workflow:dump "${:arg_workflow}" | '.$dot.' -T"${:arg_format}"';

src/WorkflowGui/Resources/config/services.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ services:
1111
- '@Youwe\Pimcore\WorkflowGui\Resolver\ConfigFileResolver'
1212

1313
Youwe\Pimcore\WorkflowGui\Controller\WorkflowController:
14-
arguments:
14+
arguments:
1515
- '@Youwe\Pimcore\WorkflowGui\Repository\WorkflowRepository'
1616
- '@Youwe\Pimcore\WorkflowGui\Resolver\ConfigFileResolver'
1717
- '@kernel'
1818
- '@Pimcore\Cache\Symfony\CacheClearer'
19-
tags:
20-
- { name: controller.service_arguments }
21-
calls:
22-
- { method: setContainer, arguments: [ '@service_container' ] }
19+
- '@translator'
20+
tags: ['controller.service_arguments', 'container.service_subscriber']
21+
calls:
22+
- { method: setContainer, arguments: [ '@Psr\Container\ContainerInterface' ] }
2323
- { method: setTokenResolver, arguments: [ '@Pimcore\Security\User\TokenStorageUserResolver' ] }
2424
- { method: setPimcoreSerializer, arguments: [ '@pimcore.serializer' ] }

0 commit comments

Comments
 (0)