@@ -18,40 +18,40 @@ |
||
18 | 18 | */ |
19 | 19 | abstract class AbstractTool implements ToolInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * @param string $templateNameAndPath |
|
23 | - * @return StandaloneView |
|
24 | - * @throws \InvalidArgumentException |
|
25 | - */ |
|
26 | - protected function initializeStandaloneView($templateNameAndPath) |
|
27 | - { |
|
28 | - $templateNameAndPath = GeneralUtility::getFileAbsFileName($templateNameAndPath); |
|
21 | + /** |
|
22 | + * @param string $templateNameAndPath |
|
23 | + * @return StandaloneView |
|
24 | + * @throws \InvalidArgumentException |
|
25 | + */ |
|
26 | + protected function initializeStandaloneView($templateNameAndPath) |
|
27 | + { |
|
28 | + $templateNameAndPath = GeneralUtility::getFileAbsFileName($templateNameAndPath); |
|
29 | 29 | |
30 | - /** @var StandaloneView $view */ |
|
31 | - $view = GeneralUtility::makeInstance(StandaloneView::class); |
|
30 | + /** @var StandaloneView $view */ |
|
31 | + $view = GeneralUtility::makeInstance(StandaloneView::class); |
|
32 | 32 | |
33 | - $view->setTemplatePathAndFilename($templateNameAndPath); |
|
34 | - return $view; |
|
35 | - } |
|
33 | + $view->setTemplatePathAndFilename($templateNameAndPath); |
|
34 | + return $view; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Returns an instance of the current Backend User. |
|
39 | - * |
|
40 | - * @return BackendUserAuthentication |
|
41 | - */ |
|
42 | - protected function getBackendUser() |
|
43 | - { |
|
44 | - return $GLOBALS['BE_USER']; |
|
45 | - } |
|
37 | + /** |
|
38 | + * Returns an instance of the current Backend User. |
|
39 | + * |
|
40 | + * @return BackendUserAuthentication |
|
41 | + */ |
|
42 | + protected function getBackendUser() |
|
43 | + { |
|
44 | + return $GLOBALS['BE_USER']; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Get the Vidi Module Loader. |
|
49 | - * |
|
50 | - * @return ModuleLoader |
|
51 | - * @throws \InvalidArgumentException |
|
52 | - */ |
|
53 | - protected function getModuleLoader() |
|
54 | - { |
|
55 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
56 | - } |
|
47 | + /** |
|
48 | + * Get the Vidi Module Loader. |
|
49 | + * |
|
50 | + * @return ModuleLoader |
|
51 | + * @throws \InvalidArgumentException |
|
52 | + */ |
|
53 | + protected function getModuleLoader() |
|
54 | + { |
|
55 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
56 | + } |
|
57 | 57 | } |
@@ -18,173 +18,173 @@ |
||
18 | 18 | */ |
19 | 19 | class ToolRegistry implements SingletonInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $tools = []; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $overriddenPermissions = []; |
|
30 | - |
|
31 | - /** |
|
32 | - * Returns a class instance. |
|
33 | - * |
|
34 | - * @return \Fab\Vidi\Tool\ToolRegistry|object |
|
35 | - */ |
|
36 | - public static function getInstance() |
|
37 | - { |
|
38 | - return GeneralUtility::makeInstance(\Fab\Vidi\Tool\ToolRegistry::class); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Register a tool for a data type. |
|
43 | - * |
|
44 | - * @param string $dataType corresponds to the table name or can be "*" for all data types. |
|
45 | - * @param string $toolName class name which must implement "ToolInterface". |
|
46 | - * @return $this |
|
47 | - */ |
|
48 | - public function register($dataType, $toolName) |
|
49 | - { |
|
50 | - if (!isset($this->tools[$dataType])) { |
|
51 | - $this->tools[$dataType] = []; |
|
52 | - } |
|
53 | - |
|
54 | - $this->tools[$dataType][] = $toolName; |
|
55 | - return $this; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Override permissions for a tool by passing a Closure that will be evaluated when checking permissions. |
|
60 | - * |
|
61 | - * @param string $dataType corresponds to the table name or can be "*" for all data types. |
|
62 | - * @param string $toolName class name which must implement "ToolInterface". |
|
63 | - * @param $permission |
|
64 | - * @return $this |
|
65 | - */ |
|
66 | - public function overridePermission($dataType, $toolName, Closure $permission) |
|
67 | - { |
|
68 | - if (empty($this->overriddenPermissions[$dataType])) { |
|
69 | - $this->overriddenPermissions[$dataType] = []; |
|
70 | - } |
|
71 | - |
|
72 | - $this->overriddenPermissions[$dataType][$toolName] = $permission; |
|
73 | - return $this; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Un-Register a tool for a given data type. |
|
78 | - * |
|
79 | - * @param string $dataType corresponds to the table name or can be "*" for all data types. |
|
80 | - * @param string $toolName class name which must implement "ToolInterface". |
|
81 | - * @return $this |
|
82 | - */ |
|
83 | - public function unRegister($dataType, $toolName) |
|
84 | - { |
|
85 | - if ($this->hasTools($dataType, $toolName)) { |
|
86 | - $toolPosition = array_search($toolName, $this->tools['*']); |
|
87 | - if ($toolPosition !== false) { |
|
88 | - unset($this->tools['*'][$toolPosition]); |
|
89 | - } |
|
90 | - |
|
91 | - $toolPosition = array_search($toolName, $this->tools[$dataType]); |
|
92 | - if ($toolPosition !== false) { |
|
93 | - unset($this->tools[$dataType][$toolPosition]); |
|
94 | - } |
|
95 | - } |
|
96 | - |
|
97 | - return $this; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Tell whether the given data type has any tools registered. |
|
102 | - * |
|
103 | - * @param string $dataType |
|
104 | - * @return bool |
|
105 | - */ |
|
106 | - public function hasAnyTools($dataType) |
|
107 | - { |
|
108 | - $tools = $this->getTools($dataType); |
|
109 | - return !empty($tools); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Tell whether the given data type has this $tool. |
|
114 | - * |
|
115 | - * @param string $dataType |
|
116 | - * @param string $tool |
|
117 | - * @return bool |
|
118 | - */ |
|
119 | - public function hasTools($dataType, $tool) |
|
120 | - { |
|
121 | - return in_array($tool, $this->tools['*']) || in_array($tool, $this->tools[$dataType]); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Tell whether the given tool is allowed for this data type. |
|
126 | - * |
|
127 | - * @param string $dataType |
|
128 | - * @param string $toolName |
|
129 | - * @return bool |
|
130 | - */ |
|
131 | - public function isAllowed($dataType, $toolName) |
|
132 | - { |
|
133 | - $isAllowed = false; |
|
134 | - |
|
135 | - if ($this->hasTools($dataType, $toolName)) { |
|
136 | - $permission = $this->getOverriddenPermission($dataType, $toolName); |
|
137 | - if (!is_null($permission)) { |
|
138 | - $isAllowed = $permission(); |
|
139 | - } else { |
|
140 | - /** @var ToolInterface $toolName */ |
|
141 | - $toolName = GeneralUtility::makeInstance($toolName); |
|
142 | - $isAllowed = $toolName->isShown(); |
|
143 | - } |
|
144 | - } |
|
145 | - return $isAllowed; |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Get Registered tools. |
|
150 | - * |
|
151 | - * @param string $dataType |
|
152 | - * @return ToolInterface[] |
|
153 | - */ |
|
154 | - public function getTools($dataType) |
|
155 | - { |
|
156 | - $tools = []; |
|
157 | - |
|
158 | - foreach (array($dataType, '*') as $toolSource) { |
|
159 | - if (isset($this->tools[$toolSource])) { |
|
160 | - $toolNames = $this->tools[$toolSource]; |
|
161 | - |
|
162 | - foreach ($toolNames as $toolName) { |
|
163 | - /** @var ToolInterface $tool */ |
|
164 | - if ($this->isAllowed($dataType, $toolName)) { |
|
165 | - $tools[] = GeneralUtility::makeInstance($toolName); |
|
166 | - } |
|
167 | - } |
|
168 | - } |
|
169 | - } |
|
170 | - return $tools; |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Get the proper permission for a tool. |
|
175 | - * |
|
176 | - * @param string $dataType corresponds to the table name or can be "*" for all data types. |
|
177 | - * @param string $toolName class name which must implement "ToolInterface". |
|
178 | - * @return null|Closure |
|
179 | - */ |
|
180 | - protected function getOverriddenPermission($dataType, $toolName) |
|
181 | - { |
|
182 | - $permission = null; |
|
183 | - if (isset($this->overriddenPermissions[$dataType][$toolName])) { |
|
184 | - $permission = $this->overriddenPermissions[$dataType][$toolName]; |
|
185 | - } elseif (isset($this->overriddenPermissions['*'][$toolName])) { |
|
186 | - $permission = $this->overriddenPermissions['*'][$toolName]; |
|
187 | - } |
|
188 | - return $permission; |
|
189 | - } |
|
21 | + /** |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $tools = []; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $overriddenPermissions = []; |
|
30 | + |
|
31 | + /** |
|
32 | + * Returns a class instance. |
|
33 | + * |
|
34 | + * @return \Fab\Vidi\Tool\ToolRegistry|object |
|
35 | + */ |
|
36 | + public static function getInstance() |
|
37 | + { |
|
38 | + return GeneralUtility::makeInstance(\Fab\Vidi\Tool\ToolRegistry::class); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Register a tool for a data type. |
|
43 | + * |
|
44 | + * @param string $dataType corresponds to the table name or can be "*" for all data types. |
|
45 | + * @param string $toolName class name which must implement "ToolInterface". |
|
46 | + * @return $this |
|
47 | + */ |
|
48 | + public function register($dataType, $toolName) |
|
49 | + { |
|
50 | + if (!isset($this->tools[$dataType])) { |
|
51 | + $this->tools[$dataType] = []; |
|
52 | + } |
|
53 | + |
|
54 | + $this->tools[$dataType][] = $toolName; |
|
55 | + return $this; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Override permissions for a tool by passing a Closure that will be evaluated when checking permissions. |
|
60 | + * |
|
61 | + * @param string $dataType corresponds to the table name or can be "*" for all data types. |
|
62 | + * @param string $toolName class name which must implement "ToolInterface". |
|
63 | + * @param $permission |
|
64 | + * @return $this |
|
65 | + */ |
|
66 | + public function overridePermission($dataType, $toolName, Closure $permission) |
|
67 | + { |
|
68 | + if (empty($this->overriddenPermissions[$dataType])) { |
|
69 | + $this->overriddenPermissions[$dataType] = []; |
|
70 | + } |
|
71 | + |
|
72 | + $this->overriddenPermissions[$dataType][$toolName] = $permission; |
|
73 | + return $this; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Un-Register a tool for a given data type. |
|
78 | + * |
|
79 | + * @param string $dataType corresponds to the table name or can be "*" for all data types. |
|
80 | + * @param string $toolName class name which must implement "ToolInterface". |
|
81 | + * @return $this |
|
82 | + */ |
|
83 | + public function unRegister($dataType, $toolName) |
|
84 | + { |
|
85 | + if ($this->hasTools($dataType, $toolName)) { |
|
86 | + $toolPosition = array_search($toolName, $this->tools['*']); |
|
87 | + if ($toolPosition !== false) { |
|
88 | + unset($this->tools['*'][$toolPosition]); |
|
89 | + } |
|
90 | + |
|
91 | + $toolPosition = array_search($toolName, $this->tools[$dataType]); |
|
92 | + if ($toolPosition !== false) { |
|
93 | + unset($this->tools[$dataType][$toolPosition]); |
|
94 | + } |
|
95 | + } |
|
96 | + |
|
97 | + return $this; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Tell whether the given data type has any tools registered. |
|
102 | + * |
|
103 | + * @param string $dataType |
|
104 | + * @return bool |
|
105 | + */ |
|
106 | + public function hasAnyTools($dataType) |
|
107 | + { |
|
108 | + $tools = $this->getTools($dataType); |
|
109 | + return !empty($tools); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Tell whether the given data type has this $tool. |
|
114 | + * |
|
115 | + * @param string $dataType |
|
116 | + * @param string $tool |
|
117 | + * @return bool |
|
118 | + */ |
|
119 | + public function hasTools($dataType, $tool) |
|
120 | + { |
|
121 | + return in_array($tool, $this->tools['*']) || in_array($tool, $this->tools[$dataType]); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Tell whether the given tool is allowed for this data type. |
|
126 | + * |
|
127 | + * @param string $dataType |
|
128 | + * @param string $toolName |
|
129 | + * @return bool |
|
130 | + */ |
|
131 | + public function isAllowed($dataType, $toolName) |
|
132 | + { |
|
133 | + $isAllowed = false; |
|
134 | + |
|
135 | + if ($this->hasTools($dataType, $toolName)) { |
|
136 | + $permission = $this->getOverriddenPermission($dataType, $toolName); |
|
137 | + if (!is_null($permission)) { |
|
138 | + $isAllowed = $permission(); |
|
139 | + } else { |
|
140 | + /** @var ToolInterface $toolName */ |
|
141 | + $toolName = GeneralUtility::makeInstance($toolName); |
|
142 | + $isAllowed = $toolName->isShown(); |
|
143 | + } |
|
144 | + } |
|
145 | + return $isAllowed; |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Get Registered tools. |
|
150 | + * |
|
151 | + * @param string $dataType |
|
152 | + * @return ToolInterface[] |
|
153 | + */ |
|
154 | + public function getTools($dataType) |
|
155 | + { |
|
156 | + $tools = []; |
|
157 | + |
|
158 | + foreach (array($dataType, '*') as $toolSource) { |
|
159 | + if (isset($this->tools[$toolSource])) { |
|
160 | + $toolNames = $this->tools[$toolSource]; |
|
161 | + |
|
162 | + foreach ($toolNames as $toolName) { |
|
163 | + /** @var ToolInterface $tool */ |
|
164 | + if ($this->isAllowed($dataType, $toolName)) { |
|
165 | + $tools[] = GeneralUtility::makeInstance($toolName); |
|
166 | + } |
|
167 | + } |
|
168 | + } |
|
169 | + } |
|
170 | + return $tools; |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Get the proper permission for a tool. |
|
175 | + * |
|
176 | + * @param string $dataType corresponds to the table name or can be "*" for all data types. |
|
177 | + * @param string $toolName class name which must implement "ToolInterface". |
|
178 | + * @return null|Closure |
|
179 | + */ |
|
180 | + protected function getOverriddenPermission($dataType, $toolName) |
|
181 | + { |
|
182 | + $permission = null; |
|
183 | + if (isset($this->overriddenPermissions[$dataType][$toolName])) { |
|
184 | + $permission = $this->overriddenPermissions[$dataType][$toolName]; |
|
185 | + } elseif (isset($this->overriddenPermissions['*'][$toolName])) { |
|
186 | + $permission = $this->overriddenPermissions['*'][$toolName]; |
|
187 | + } |
|
188 | + return $permission; |
|
189 | + } |
|
190 | 190 | } |
@@ -21,212 +21,212 @@ |
||
21 | 21 | */ |
22 | 22 | class ModulePidService |
23 | 23 | { |
24 | - /** |
|
25 | - * The data type (table) |
|
26 | - * |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $dataType = ''; |
|
30 | - |
|
31 | - /** |
|
32 | - * A collection of speaking error messages why the pid is invalid. |
|
33 | - * |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $errors = []; |
|
37 | - |
|
38 | - /** |
|
39 | - * ModulePidService constructor. |
|
40 | - */ |
|
41 | - public function __construct() |
|
42 | - { |
|
43 | - $this->dataType = $this->getModuleLoader()->getDataType(); |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Returns a class instance |
|
48 | - * |
|
49 | - * @return \Fab\Vidi\Module\ModulePidService|object |
|
50 | - */ |
|
51 | - public static function getInstance() |
|
52 | - { |
|
53 | - return GeneralUtility::makeInstance(self::class); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @return bool |
|
58 | - */ |
|
59 | - public function isConfiguredPidValid(): bool |
|
60 | - { |
|
61 | - $errors = $this->validateConfiguredPid(); |
|
62 | - return empty($errors); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @return array |
|
67 | - */ |
|
68 | - public function validateConfiguredPid(): array |
|
69 | - { |
|
70 | - $configuredPid = $this->getConfiguredNewRecordPid(); |
|
71 | - $this->validateRootLevel($configuredPid); |
|
72 | - $this->validatePageExist($configuredPid); |
|
73 | - $this->validateDoktype($configuredPid); |
|
74 | - return $this->errors; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Return the default configured pid. |
|
79 | - * |
|
80 | - * @return int |
|
81 | - */ |
|
82 | - public function getConfiguredNewRecordPid(): int |
|
83 | - { |
|
84 | - if (GeneralUtility::_GP(Parameter::PID)) { |
|
85 | - $configuredPid = (int)GeneralUtility::_GP(Parameter::PID); |
|
86 | - } else { |
|
87 | - // Get pid from User TSConfig if any. |
|
88 | - $tsConfigPath = sprintf('tx_vidi.dataType.%s.storagePid', $this->dataType); |
|
89 | - $result = $this->getBackendUser()->getTSConfig($tsConfigPath); |
|
90 | - $configuredPid = isset($result['value']) |
|
91 | - ? $configuredPid = (int)$result['value'] |
|
92 | - : $this->getModuleLoader()->getDefaultPid(); |
|
93 | - } |
|
94 | - |
|
95 | - return $configuredPid; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Check if pid is 0 and given table is allowed on root level. |
|
100 | - * |
|
101 | - * @param int $configuredPid |
|
102 | - * @return void |
|
103 | - */ |
|
104 | - protected function validateRootLevel(int $configuredPid): void |
|
105 | - { |
|
106 | - if ($configuredPid > 0) { |
|
107 | - return; |
|
108 | - } |
|
109 | - |
|
110 | - $isRootLevel = (bool)Tca::table()->get('rootLevel'); |
|
111 | - if (!$isRootLevel) { |
|
112 | - $this->errors[] = sprintf( |
|
113 | - 'You are not allowed to use page id "0" unless you set $GLOBALS[\'TCA\'][\'%1$s\'][\'ctrl\'][\'rootLevel\'] = 1;', |
|
114 | - $this->dataType |
|
115 | - ); |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Check if a page exists for the configured pid |
|
121 | - * |
|
122 | - * @param int $configuredPid |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - protected function validatePageExist(int $configuredPid): void |
|
126 | - { |
|
127 | - if ($configuredPid === 0) { |
|
128 | - return; |
|
129 | - } |
|
130 | - |
|
131 | - $page = $this->getPage($configuredPid); |
|
132 | - if (empty($page)) { |
|
133 | - $this->errors[] = sprintf( |
|
134 | - 'No page found for the configured page id "%s".', |
|
135 | - $configuredPid |
|
136 | - ); |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Check if configured page is a sysfolder and if it is allowed. |
|
142 | - * |
|
143 | - * @param int $configuredPid |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - protected function validateDoktype(int $configuredPid): void |
|
147 | - { |
|
148 | - if ($configuredPid === 0) { |
|
149 | - return; |
|
150 | - } |
|
151 | - |
|
152 | - $page = $this->getPage($configuredPid); |
|
153 | - if (!empty($page) |
|
154 | - && (int)$page['doktype'] !== PageRepository::DOKTYPE_SYSFOLDER |
|
155 | - && !$this->isTableAllowedOnStandardPages() |
|
156 | - && $this->getModuleLoader()->hasComponentInDocHeader(NewButton::class)) { |
|
157 | - $this->errors[] = sprintf( |
|
158 | - 'The page with the id "%s" either has to be of the type "folder" (doktype=254) or the table "%s" has to be allowed on standard pages.', |
|
159 | - $configuredPid, |
|
160 | - $this->dataType |
|
161 | - ); |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Check if given table is allowed on standard pages |
|
167 | - * |
|
168 | - * @return bool |
|
169 | - * @see \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages() |
|
170 | - */ |
|
171 | - protected function isTableAllowedOnStandardPages(): bool |
|
172 | - { |
|
173 | - $allowedTables = explode(',', $GLOBALS['PAGES_TYPES']['default']['allowedTables']); |
|
174 | - return in_array($this->dataType, $allowedTables, true); |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Returns the page record of the configured pid |
|
179 | - * |
|
180 | - * @param int $configuredPid |
|
181 | - * @return array |
|
182 | - */ |
|
183 | - protected function getPage(int $configuredPid): ?array |
|
184 | - { |
|
185 | - $query = $this->getQueryBuilder('pages'); |
|
186 | - $query->getRestrictions()->removeAll(); // we are in BE context. |
|
187 | - |
|
188 | - $page = $query->select('doktype') |
|
189 | - ->from('pages') |
|
190 | - ->where( |
|
191 | - 'deleted = 0', |
|
192 | - 'uid = ' . $configuredPid |
|
193 | - ) |
|
194 | - ->execute() |
|
195 | - ->fetch(); |
|
196 | - |
|
197 | - return is_array($page) |
|
198 | - ? $page |
|
199 | - : []; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * @param string $tableName |
|
204 | - * @return object|QueryBuilder |
|
205 | - */ |
|
206 | - protected function getQueryBuilder($tableName): QueryBuilder |
|
207 | - { |
|
208 | - /** @var ConnectionPool $connectionPool */ |
|
209 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
210 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Returns an instance of the current Backend User. |
|
215 | - * |
|
216 | - * @return BackendUserAuthentication |
|
217 | - */ |
|
218 | - protected function getBackendUser() |
|
219 | - { |
|
220 | - return $GLOBALS['BE_USER']; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Get the Vidi Module Loader. |
|
225 | - * |
|
226 | - * @return ModuleLoader|object |
|
227 | - */ |
|
228 | - protected function getModuleLoader() |
|
229 | - { |
|
230 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
231 | - } |
|
24 | + /** |
|
25 | + * The data type (table) |
|
26 | + * |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $dataType = ''; |
|
30 | + |
|
31 | + /** |
|
32 | + * A collection of speaking error messages why the pid is invalid. |
|
33 | + * |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $errors = []; |
|
37 | + |
|
38 | + /** |
|
39 | + * ModulePidService constructor. |
|
40 | + */ |
|
41 | + public function __construct() |
|
42 | + { |
|
43 | + $this->dataType = $this->getModuleLoader()->getDataType(); |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Returns a class instance |
|
48 | + * |
|
49 | + * @return \Fab\Vidi\Module\ModulePidService|object |
|
50 | + */ |
|
51 | + public static function getInstance() |
|
52 | + { |
|
53 | + return GeneralUtility::makeInstance(self::class); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | + public function isConfiguredPidValid(): bool |
|
60 | + { |
|
61 | + $errors = $this->validateConfiguredPid(); |
|
62 | + return empty($errors); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @return array |
|
67 | + */ |
|
68 | + public function validateConfiguredPid(): array |
|
69 | + { |
|
70 | + $configuredPid = $this->getConfiguredNewRecordPid(); |
|
71 | + $this->validateRootLevel($configuredPid); |
|
72 | + $this->validatePageExist($configuredPid); |
|
73 | + $this->validateDoktype($configuredPid); |
|
74 | + return $this->errors; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Return the default configured pid. |
|
79 | + * |
|
80 | + * @return int |
|
81 | + */ |
|
82 | + public function getConfiguredNewRecordPid(): int |
|
83 | + { |
|
84 | + if (GeneralUtility::_GP(Parameter::PID)) { |
|
85 | + $configuredPid = (int)GeneralUtility::_GP(Parameter::PID); |
|
86 | + } else { |
|
87 | + // Get pid from User TSConfig if any. |
|
88 | + $tsConfigPath = sprintf('tx_vidi.dataType.%s.storagePid', $this->dataType); |
|
89 | + $result = $this->getBackendUser()->getTSConfig($tsConfigPath); |
|
90 | + $configuredPid = isset($result['value']) |
|
91 | + ? $configuredPid = (int)$result['value'] |
|
92 | + : $this->getModuleLoader()->getDefaultPid(); |
|
93 | + } |
|
94 | + |
|
95 | + return $configuredPid; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Check if pid is 0 and given table is allowed on root level. |
|
100 | + * |
|
101 | + * @param int $configuredPid |
|
102 | + * @return void |
|
103 | + */ |
|
104 | + protected function validateRootLevel(int $configuredPid): void |
|
105 | + { |
|
106 | + if ($configuredPid > 0) { |
|
107 | + return; |
|
108 | + } |
|
109 | + |
|
110 | + $isRootLevel = (bool)Tca::table()->get('rootLevel'); |
|
111 | + if (!$isRootLevel) { |
|
112 | + $this->errors[] = sprintf( |
|
113 | + 'You are not allowed to use page id "0" unless you set $GLOBALS[\'TCA\'][\'%1$s\'][\'ctrl\'][\'rootLevel\'] = 1;', |
|
114 | + $this->dataType |
|
115 | + ); |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Check if a page exists for the configured pid |
|
121 | + * |
|
122 | + * @param int $configuredPid |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + protected function validatePageExist(int $configuredPid): void |
|
126 | + { |
|
127 | + if ($configuredPid === 0) { |
|
128 | + return; |
|
129 | + } |
|
130 | + |
|
131 | + $page = $this->getPage($configuredPid); |
|
132 | + if (empty($page)) { |
|
133 | + $this->errors[] = sprintf( |
|
134 | + 'No page found for the configured page id "%s".', |
|
135 | + $configuredPid |
|
136 | + ); |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Check if configured page is a sysfolder and if it is allowed. |
|
142 | + * |
|
143 | + * @param int $configuredPid |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + protected function validateDoktype(int $configuredPid): void |
|
147 | + { |
|
148 | + if ($configuredPid === 0) { |
|
149 | + return; |
|
150 | + } |
|
151 | + |
|
152 | + $page = $this->getPage($configuredPid); |
|
153 | + if (!empty($page) |
|
154 | + && (int)$page['doktype'] !== PageRepository::DOKTYPE_SYSFOLDER |
|
155 | + && !$this->isTableAllowedOnStandardPages() |
|
156 | + && $this->getModuleLoader()->hasComponentInDocHeader(NewButton::class)) { |
|
157 | + $this->errors[] = sprintf( |
|
158 | + 'The page with the id "%s" either has to be of the type "folder" (doktype=254) or the table "%s" has to be allowed on standard pages.', |
|
159 | + $configuredPid, |
|
160 | + $this->dataType |
|
161 | + ); |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Check if given table is allowed on standard pages |
|
167 | + * |
|
168 | + * @return bool |
|
169 | + * @see \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages() |
|
170 | + */ |
|
171 | + protected function isTableAllowedOnStandardPages(): bool |
|
172 | + { |
|
173 | + $allowedTables = explode(',', $GLOBALS['PAGES_TYPES']['default']['allowedTables']); |
|
174 | + return in_array($this->dataType, $allowedTables, true); |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Returns the page record of the configured pid |
|
179 | + * |
|
180 | + * @param int $configuredPid |
|
181 | + * @return array |
|
182 | + */ |
|
183 | + protected function getPage(int $configuredPid): ?array |
|
184 | + { |
|
185 | + $query = $this->getQueryBuilder('pages'); |
|
186 | + $query->getRestrictions()->removeAll(); // we are in BE context. |
|
187 | + |
|
188 | + $page = $query->select('doktype') |
|
189 | + ->from('pages') |
|
190 | + ->where( |
|
191 | + 'deleted = 0', |
|
192 | + 'uid = ' . $configuredPid |
|
193 | + ) |
|
194 | + ->execute() |
|
195 | + ->fetch(); |
|
196 | + |
|
197 | + return is_array($page) |
|
198 | + ? $page |
|
199 | + : []; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * @param string $tableName |
|
204 | + * @return object|QueryBuilder |
|
205 | + */ |
|
206 | + protected function getQueryBuilder($tableName): QueryBuilder |
|
207 | + { |
|
208 | + /** @var ConnectionPool $connectionPool */ |
|
209 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
210 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * Returns an instance of the current Backend User. |
|
215 | + * |
|
216 | + * @return BackendUserAuthentication |
|
217 | + */ |
|
218 | + protected function getBackendUser() |
|
219 | + { |
|
220 | + return $GLOBALS['BE_USER']; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Get the Vidi Module Loader. |
|
225 | + * |
|
226 | + * @return ModuleLoader|object |
|
227 | + */ |
|
228 | + protected function getModuleLoader() |
|
229 | + { |
|
230 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
231 | + } |
|
232 | 232 | } |
@@ -189,7 +189,7 @@ |
||
189 | 189 | ->from('pages') |
190 | 190 | ->where( |
191 | 191 | 'deleted = 0', |
192 | - 'uid = ' . $configuredPid |
|
192 | + 'uid = '.$configuredPid |
|
193 | 193 | ) |
194 | 194 | ->execute() |
195 | 195 | ->fetch(); |
@@ -16,7 +16,7 @@ |
||
16 | 16 | */ |
17 | 17 | class Access extends Enumeration |
18 | 18 | { |
19 | - public const USER = 'user,group'; |
|
19 | + public const USER = 'user,group'; |
|
20 | 20 | |
21 | - public const ADMIN = 'admin'; |
|
21 | + public const ADMIN = 'admin'; |
|
22 | 22 | } |
@@ -16,9 +16,9 @@ |
||
16 | 16 | */ |
17 | 17 | class Parameter extends Enumeration |
18 | 18 | { |
19 | - public const PID = 'id'; |
|
19 | + public const PID = 'id'; |
|
20 | 20 | |
21 | - public const SUBMODULE = 'vidiModuleCode'; |
|
21 | + public const SUBMODULE = 'vidiModuleCode'; |
|
22 | 22 | |
23 | - public const MODULE = 'route'; |
|
23 | + public const MODULE = 'route'; |
|
24 | 24 | } |
@@ -16,13 +16,13 @@ |
||
16 | 16 | */ |
17 | 17 | class ModuleName extends Enumeration |
18 | 18 | { |
19 | - public const WEB = 'web'; |
|
19 | + public const WEB = 'web'; |
|
20 | 20 | |
21 | - public const FILE = 'file'; |
|
21 | + public const FILE = 'file'; |
|
22 | 22 | |
23 | - public const USER = 'user'; |
|
23 | + public const USER = 'user'; |
|
24 | 24 | |
25 | - public const ADMIN = 'admin'; |
|
25 | + public const ADMIN = 'admin'; |
|
26 | 26 | |
27 | - public const SYSTEM = 'system'; |
|
27 | + public const SYSTEM = 'system'; |
|
28 | 28 | } |
@@ -16,19 +16,19 @@ |
||
16 | 16 | */ |
17 | 17 | class ModulePosition extends Enumeration |
18 | 18 | { |
19 | - public const DOC_HEADER = 'doc-header'; |
|
19 | + public const DOC_HEADER = 'doc-header'; |
|
20 | 20 | |
21 | - public const TOP = 'top'; |
|
21 | + public const TOP = 'top'; |
|
22 | 22 | |
23 | - public const BOTTOM = 'bottom'; |
|
23 | + public const BOTTOM = 'bottom'; |
|
24 | 24 | |
25 | - public const LEFT = 'left'; |
|
25 | + public const LEFT = 'left'; |
|
26 | 26 | |
27 | - public const RIGHT = 'right'; |
|
27 | + public const RIGHT = 'right'; |
|
28 | 28 | |
29 | - public const GRID = 'grid'; |
|
29 | + public const GRID = 'grid'; |
|
30 | 30 | |
31 | - public const BUTTONS = 'buttons'; |
|
31 | + public const BUTTONS = 'buttons'; |
|
32 | 32 | |
33 | - public const MENU_MASS_ACTION = 'menu-mass-action'; |
|
33 | + public const MENU_MASS_ACTION = 'menu-mass-action'; |
|
34 | 34 | } |
@@ -14,23 +14,23 @@ |
||
14 | 14 | */ |
15 | 15 | class ConfigurablePart |
16 | 16 | { |
17 | - public const __default = ''; |
|
18 | - public const EXCLUDED_FIELDS = 'excluded_fields'; |
|
19 | - public const MENU_VISIBLE_ITEMS = 'menuVisibleItems'; |
|
20 | - public const MENU_VISIBLE_ITEMS_DEFAULT = 'menuVisibleItemsDefault'; |
|
17 | + public const __default = ''; |
|
18 | + public const EXCLUDED_FIELDS = 'excluded_fields'; |
|
19 | + public const MENU_VISIBLE_ITEMS = 'menuVisibleItems'; |
|
20 | + public const MENU_VISIBLE_ITEMS_DEFAULT = 'menuVisibleItemsDefault'; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Get the valid values for this enum. |
|
24 | - * |
|
25 | - * @param boolean $include_default |
|
26 | - * @return array |
|
27 | - */ |
|
28 | - public static function getParts($include_default = false) |
|
29 | - { |
|
30 | - return array( |
|
31 | - 'EXCLUDED_FIELDS' => self::EXCLUDED_FIELDS, |
|
32 | - 'MENU_VISIBLE_ITEMS' => self::MENU_VISIBLE_ITEMS, |
|
33 | - 'MENU_VISIBLE_ITEMS_DEFAULT' => self::MENU_VISIBLE_ITEMS_DEFAULT, |
|
34 | - ); |
|
35 | - } |
|
22 | + /** |
|
23 | + * Get the valid values for this enum. |
|
24 | + * |
|
25 | + * @param boolean $include_default |
|
26 | + * @return array |
|
27 | + */ |
|
28 | + public static function getParts($include_default = false) |
|
29 | + { |
|
30 | + return array( |
|
31 | + 'EXCLUDED_FIELDS' => self::EXCLUDED_FIELDS, |
|
32 | + 'MENU_VISIBLE_ITEMS' => self::MENU_VISIBLE_ITEMS, |
|
33 | + 'MENU_VISIBLE_ITEMS_DEFAULT' => self::MENU_VISIBLE_ITEMS_DEFAULT, |
|
34 | + ); |
|
35 | + } |
|
36 | 36 | } |
@@ -17,68 +17,68 @@ |
||
17 | 17 | */ |
18 | 18 | class DataHandlerFactory implements SingletonInterface |
19 | 19 | { |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $actionName = ''; |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $actionName = ''; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - protected $dataType = ''; |
|
25 | + /** |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + protected $dataType = ''; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Default is CoreDataHandler which wraps the Core DataHandler. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - protected $defaultDataHandler = 'Fab\Vidi\DataHandler\CoreDataHandler'; |
|
30 | + /** |
|
31 | + * Default is CoreDataHandler which wraps the Core DataHandler. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + protected $defaultDataHandler = 'Fab\Vidi\DataHandler\CoreDataHandler'; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param string $actionName |
|
39 | - * @return $this |
|
40 | - */ |
|
41 | - public function action($actionName) |
|
42 | - { |
|
43 | - $this->actionName = $actionName; |
|
44 | - return $this; |
|
45 | - } |
|
37 | + /** |
|
38 | + * @param string $actionName |
|
39 | + * @return $this |
|
40 | + */ |
|
41 | + public function action($actionName) |
|
42 | + { |
|
43 | + $this->actionName = $actionName; |
|
44 | + return $this; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param string $dataType |
|
49 | - * @return $this |
|
50 | - */ |
|
51 | - public function forType($dataType) |
|
52 | - { |
|
53 | - $this->dataType = $dataType; |
|
54 | - return $this; |
|
55 | - } |
|
47 | + /** |
|
48 | + * @param string $dataType |
|
49 | + * @return $this |
|
50 | + */ |
|
51 | + public function forType($dataType) |
|
52 | + { |
|
53 | + $this->dataType = $dataType; |
|
54 | + return $this; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Returns a Data Handler instance. |
|
59 | - * |
|
60 | - * @throws \Exception |
|
61 | - * @return DataHandlerInterface |
|
62 | - */ |
|
63 | - public function getDataHandler() |
|
64 | - { |
|
65 | - if (empty($this->dataType)) { |
|
66 | - throw new \Exception('Attribute $this->dataType can not be empty', 1410001035); |
|
67 | - } |
|
57 | + /** |
|
58 | + * Returns a Data Handler instance. |
|
59 | + * |
|
60 | + * @throws \Exception |
|
61 | + * @return DataHandlerInterface |
|
62 | + */ |
|
63 | + public function getDataHandler() |
|
64 | + { |
|
65 | + if (empty($this->dataType)) { |
|
66 | + throw new \Exception('Attribute $this->dataType can not be empty', 1410001035); |
|
67 | + } |
|
68 | 68 | |
69 | - if (empty($this->actionName)) { |
|
70 | - throw new \Exception('Attribute $this->actionName can not be empty', 1410001036); |
|
71 | - } |
|
69 | + if (empty($this->actionName)) { |
|
70 | + throw new \Exception('Attribute $this->actionName can not be empty', 1410001036); |
|
71 | + } |
|
72 | 72 | |
73 | - if (isset($GLOBALS['TCA'][$this->dataType]['vidi']['data_handler'][$this->actionName])) { |
|
74 | - $className = $GLOBALS['TCA'][$this->dataType]['vidi']['data_handler'][$this->actionName]; |
|
75 | - } elseif (isset($GLOBALS['TCA'][$this->dataType]['vidi']['data_handler']['*'])) { |
|
76 | - $className = $GLOBALS['TCA'][$this->dataType]['vidi']['data_handler']['*']; |
|
77 | - } else { |
|
78 | - $className = $this->defaultDataHandler; |
|
79 | - } |
|
73 | + if (isset($GLOBALS['TCA'][$this->dataType]['vidi']['data_handler'][$this->actionName])) { |
|
74 | + $className = $GLOBALS['TCA'][$this->dataType]['vidi']['data_handler'][$this->actionName]; |
|
75 | + } elseif (isset($GLOBALS['TCA'][$this->dataType]['vidi']['data_handler']['*'])) { |
|
76 | + $className = $GLOBALS['TCA'][$this->dataType]['vidi']['data_handler']['*']; |
|
77 | + } else { |
|
78 | + $className = $this->defaultDataHandler; |
|
79 | + } |
|
80 | 80 | |
81 | - $dataHandler = GeneralUtility::makeInstance($className); |
|
82 | - return $dataHandler; |
|
83 | - } |
|
81 | + $dataHandler = GeneralUtility::makeInstance($className); |
|
82 | + return $dataHandler; |
|
83 | + } |
|
84 | 84 | } |