This repository was archived by the owner on Aug 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditorController.php
More file actions
108 lines (99 loc) · 3.92 KB
/
EditorController.php
File metadata and controls
108 lines (99 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
declare(strict_types=1);
/*
* This file is part of the Zikula package.
*
* Copyright Zikula - https://ziku.la/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zikula\Bundle\WorkflowBundle\Controller;
use ReflectionClass;
use ReflectionException;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Workflow\MarkingStore\MethodMarkingStore;
use Symfony\Component\Workflow\Registry;
use Symfony\Contracts\Translation\TranslatorInterface;
use Zikula\PermissionsModule\Annotation\PermissionCheck;
use Zikula\ThemeModule\Engine\Annotation\Theme;
/**
* Workflow editor controller class.
*
* @Route("/editor")
* @PermissionCheck("admin")
*/
class EditorController extends AbstractController
{
/**
* This is the default action handling the index action.
*
* @Route("/index",
* methods = {"GET"}
* )
* @Theme("admin")
* @Template("@ZikulaWorkflow/Editor/index.html.twig")
*
* @throws NotFoundHttpException Thrown if the desired workflow could not be found
*/
public function index(
Request $request,
Registry $workflowRegistry,
TranslatorInterface $translator,
ContainerInterface $container
): array {
$workflowType = 'workflow';
$workflowName = $workflowType . '.' . $request->query->get('workflow', '');
if (!$container->has($workflowName)) {
$workflowType = 'state_machine';
$workflowName = $workflowType . '.' . $request->query->get('workflow', '');
}
if (!$container->has($workflowName)) {
throw new NotFoundHttpException($translator->trans('Workflow "%workflow%" not found.', ['%workflow%' => $workflowName]));
}
$workflow = $container->get($workflowName);
$workflowDefinition = $workflow->getDefinition();
$markingStoreType = '';
$markingStoreField = '';
$supportedEntityClassNames = [];
try {
$markingStore = $workflow->getMarkingStore();
if ($markingStore instanceof MethodMarkingStore) {
$markingStoreType = 'method';
$reflection = new ReflectionClass(MethodMarkingStore::class);
$propertyProperty = $reflection->getProperty('property');
$propertyProperty->setAccessible(true);
$markingStoreField = $propertyProperty->getValue($markingStore);
}
$reflection = new ReflectionClass(get_class($workflowRegistry));
$workflowsProperty = $reflection->getProperty('workflows');
$workflowsProperty->setAccessible(true);
$workflows = $workflowsProperty->getValue($workflowRegistry);
foreach ($workflows as list($aWorkflow, $workflowClass)) {
if ($aWorkflow->getName() !== $workflow->getName()) {
continue;
}
if (method_exists($workflowClass, 'getClassName')) {
$workflowClass = $workflowClass->getClassName();
}
$supportedEntityClassNames[] = $workflowClass;
}
} catch (ReflectionException $exception) {
$markingStoreType = 'method';
$markingStoreField = 'state';
}
return [
'name' => $workflow->getName(),
'type' => $workflowType,
'markingStoreType' => $markingStoreType,
'markingStoreField' => $markingStoreField,
'supportedEntities' => $supportedEntityClassNames,
'workflow' => $workflowDefinition
];
}
}