Conditions | 54 |
Paths | > 20000 |
Total Lines | 240 |
Code Lines | 170 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
149 | public function main() |
||
150 | { |
||
151 | $lang = $this->getLanguageService(); |
||
152 | $POST = GeneralUtility::_POST(); |
||
153 | |||
154 | // Checking for more than one template an if, set a menu... |
||
155 | $manyTemplatesMenu = $this->pObj->templateMenu(); |
||
156 | $template_uid = 0; |
||
157 | if ($manyTemplatesMenu) { |
||
158 | $template_uid = $this->pObj->MOD_SETTINGS['templatesOnPage']; |
||
159 | } |
||
160 | $bType = $this->pObj->MOD_SETTINGS['ts_browser_type']; |
||
161 | $existTemplate = $this->initialize_editor($this->pObj->id, $template_uid); |
||
162 | // initialize |
||
163 | $assigns = []; |
||
164 | $assigns['LLPrefix'] = 'LLL:' . $this->localLanguageFilePath . ':'; |
||
165 | $assigns['existTemplate'] = $existTemplate; |
||
166 | $assigns['tsBrowserType'] = $this->pObj->MOD_SETTINGS['ts_browser_type']; |
||
167 | if ($existTemplate) { |
||
168 | $assigns['templateRecord'] = $this->templateRow; |
||
169 | $assigns['linkWrapTemplateTitle'] = $this->pObj->linkWrapTemplateTitle($this->templateRow['title'], ($bType === 'setup' ? 'config' : 'constants')); |
||
170 | $assigns['manyTemplatesMenu'] = $manyTemplatesMenu; |
||
171 | |||
172 | if ($POST['add_property'] || $POST['update_value'] || $POST['clear_object']) { |
||
173 | // add property |
||
174 | $line = ''; |
||
175 | if (is_array($POST['data'])) { |
||
176 | $name = key($POST['data']); |
||
177 | if ($POST['data'][$name]['name'] !== '') { |
||
178 | // Workaround for this special case: User adds a key and submits by pressing the return key. The form however will use "add_property" which is the name of the first submit button in this form. |
||
179 | unset($POST['update_value']); |
||
180 | $POST['add_property'] = 'Add'; |
||
181 | } |
||
182 | if ($POST['add_property']) { |
||
183 | $property = trim($POST['data'][$name]['name']); |
||
184 | if (preg_replace('/[^a-zA-Z0-9_\\.]*/', '', $property) != $property) { |
||
185 | $badPropertyMessage = GeneralUtility::makeInstance(FlashMessage::class, $lang->getLL('noSpaces') . $lang->getLL('nothingUpdated'), $lang->getLL('badProperty'), FlashMessage::ERROR); |
||
186 | $this->addFlashMessage($badPropertyMessage); |
||
187 | } else { |
||
188 | $pline = $name . '.' . $property . ' = ' . trim($POST['data'][$name]['propertyValue']); |
||
189 | $propertyAddedMessage = GeneralUtility::makeInstance(FlashMessage::class, $pline, $lang->getLL('propertyAdded')); |
||
190 | $this->addFlashMessage($propertyAddedMessage); |
||
191 | $line .= LF . $pline; |
||
192 | } |
||
193 | } elseif ($POST['update_value']) { |
||
194 | $pline = $name . ' = ' . trim($POST['data'][$name]['value']); |
||
195 | $updatedMessage = GeneralUtility::makeInstance(FlashMessage::class, $pline, $lang->getLL('valueUpdated')); |
||
196 | $this->addFlashMessage($updatedMessage); |
||
197 | $line .= LF . $pline; |
||
198 | } elseif ($POST['clear_object']) { |
||
199 | if ($POST['data'][$name]['clearValue']) { |
||
200 | $pline = $name . ' >'; |
||
201 | $objectClearedMessage = GeneralUtility::makeInstance(FlashMessage::class, $pline, $lang->getLL('objectCleared')); |
||
202 | $this->addFlashMessage($objectClearedMessage); |
||
203 | $line .= LF . $pline; |
||
204 | } |
||
205 | } |
||
206 | } |
||
207 | if ($line) { |
||
208 | $saveId = $this->templateRow['_ORIG_uid'] ?: $this->templateRow['uid']; |
||
209 | // Set the data to be saved |
||
210 | $recData = []; |
||
211 | $field = $bType === 'setup' ? 'config' : 'constants'; |
||
212 | $recData['sys_template'][$saveId][$field] = $this->templateRow[$field] . $line; |
||
213 | // Create new tce-object |
||
214 | $tce = GeneralUtility::makeInstance(DataHandler::class); |
||
215 | // Initialize |
||
216 | $tce->start($recData, []); |
||
217 | // Saved the stuff |
||
218 | $tce->process_datamap(); |
||
219 | // Clear the cache (note: currently only admin-users can clear the cache in tce_main.php) |
||
220 | $tce->clear_cacheCmd('all'); |
||
221 | // re-read the template ... |
||
222 | $this->initialize_editor($this->pObj->id, $template_uid); |
||
223 | } |
||
224 | } |
||
225 | } |
||
226 | $tsbr = GeneralUtility::_GET('tsbr'); |
||
227 | $update = 0; |
||
228 | if (is_array($tsbr)) { |
||
229 | // If any plus-signs were clicked, it's registred. |
||
230 | $this->pObj->MOD_SETTINGS['tsbrowser_depthKeys_' . $bType] = $this->templateService->ext_depthKeys($tsbr, $this->pObj->MOD_SETTINGS['tsbrowser_depthKeys_' . $bType]); |
||
231 | $update = 1; |
||
232 | } |
||
233 | if ($POST['Submit']) { |
||
234 | // If any POST-vars are send, update the condition array |
||
235 | $this->pObj->MOD_SETTINGS['tsbrowser_conditions'] = $POST['conditions']; |
||
236 | $update = 1; |
||
237 | } |
||
238 | if ($update) { |
||
239 | $this->getBackendUserAuthentication()->pushModuleData($this->pObj->MCONF['name'], $this->pObj->MOD_SETTINGS); |
||
240 | } |
||
241 | $this->templateService->matchAlternative = $this->pObj->MOD_SETTINGS['tsbrowser_conditions']; |
||
242 | $this->templateService->matchAlternative[] = 'dummydummydummydummydummydummydummydummydummydummydummy'; |
||
243 | // This is just here to make sure that at least one element is in the array so that the tsparser actually uses this array to match. |
||
244 | $this->templateService->constantMode = $this->pObj->MOD_SETTINGS['ts_browser_const']; |
||
245 | if ($this->pObj->sObj && $this->templateService->constantMode) { |
||
246 | $this->templateService->constantMode = 'untouched'; |
||
247 | } |
||
248 | $this->templateService->regexMode = $this->pObj->MOD_SETTINGS['ts_browser_regexsearch']; |
||
249 | $this->templateService->fixedLgd = $this->pObj->MOD_SETTINGS['ts_browser_fixedLgd']; |
||
250 | $this->templateService->linkObjects = true; |
||
251 | $this->templateService->ext_regLinenumbers = true; |
||
252 | $this->templateService->ext_regComments = $this->pObj->MOD_SETTINGS['ts_browser_showComments']; |
||
253 | $this->templateService->bType = $bType; |
||
254 | if ($this->pObj->MOD_SETTINGS['ts_browser_type'] === 'const') { |
||
255 | $this->templateService->ext_constants_BRP = (int)GeneralUtility::_GP('breakPointLN'); |
||
256 | } else { |
||
257 | $this->templateService->ext_config_BRP = (int)GeneralUtility::_GP('breakPointLN'); |
||
258 | } |
||
259 | $this->templateService->generateConfig(); |
||
260 | if ($bType === 'setup') { |
||
261 | $theSetup = $this->templateService->setup; |
||
262 | } else { |
||
263 | $theSetup = $this->templateService->setup_constants; |
||
264 | } |
||
265 | // EDIT A VALUE: |
||
266 | $assigns['typoScriptPath'] = $this->pObj->sObj; |
||
267 | if ($this->pObj->sObj) { |
||
268 | list($theSetup, $theSetupValue) = $this->templateService->ext_getSetup($theSetup, $this->pObj->sObj ? $this->pObj->sObj : ''); |
||
269 | $assigns['theSetupValue'] = $theSetupValue; |
||
270 | if ($existTemplate === false) { |
||
271 | $noTemplateMessage = GeneralUtility::makeInstance(FlashMessage::class, $lang->getLL('noCurrentTemplate'), $lang->getLL('edit'), FlashMessage::ERROR); |
||
272 | $this->addFlashMessage($noTemplateMessage); |
||
273 | } |
||
274 | // Links: |
||
275 | $urlParameters = [ |
||
276 | 'id' => $this->pObj->id |
||
277 | ]; |
||
278 | /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */ |
||
279 | $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class); |
||
280 | $aHref = (string)$uriBuilder->buildUriFromRoute('web_ts', $urlParameters); |
||
281 | $assigns['moduleUrl'] = (string)$uriBuilder->buildUriFromRoute('web_ts', $urlParameters); |
||
282 | $assigns['isNotInTopLevelKeyList'] = !isset($this->pObj->MOD_SETTINGS['ts_browser_TLKeys_' . $bType][$this->pObj->sObj]); |
||
283 | $assigns['hasProperties'] = !empty($theSetup); |
||
284 | if (!$this->pObj->MOD_SETTINGS['ts_browser_TLKeys_' . $bType][$this->pObj->sObj]) { |
||
285 | if (!empty($theSetup)) { |
||
286 | $assigns['moduleUrlObjectListAction'] = $aHref . '&addKey[' . rawurlencode($this->pObj->sObj) . ']=1&SET[ts_browser_toplevel_' . $bType . ']=' . rawurlencode($this->pObj->sObj); |
||
287 | } |
||
288 | } else { |
||
289 | $assigns['moduleUrlObjectListAction'] = $aHref . '&addKey[' . rawurlencode($this->pObj->sObj) . ']=0&SET[ts_browser_toplevel_' . $bType . ']=0'; |
||
290 | } |
||
291 | } else { |
||
292 | $this->templateService->tsbrowser_depthKeys = $this->pObj->MOD_SETTINGS['tsbrowser_depthKeys_' . $bType]; |
||
293 | if (GeneralUtility::_POST('search') && GeneralUtility::_POST('search_field')) { |
||
294 | // If any POST-vars are send, update the condition array |
||
295 | $searchString = GeneralUtility::_POST('search_field'); |
||
296 | try { |
||
297 | $this->templateService->tsbrowser_depthKeys = |
||
298 | $this->templateService->ext_getSearchKeys( |
||
299 | $theSetup, |
||
300 | '', |
||
301 | $searchString, |
||
302 | [] |
||
303 | ); |
||
304 | } catch (Exception $e) { |
||
305 | $this->addFlashMessage( |
||
306 | GeneralUtility::makeInstance(FlashMessage::class, sprintf($lang->getLL('error.' . $e->getCode()), $searchString), '', FlashMessage::ERROR) |
||
307 | ); |
||
308 | } |
||
309 | } |
||
310 | $assigns['hasTsBrowserTypes'] = is_array($this->pObj->MOD_MENU['ts_browser_type']) && count($this->pObj->MOD_MENU['ts_browser_type']) > 1; |
||
311 | if (is_array($this->pObj->MOD_MENU['ts_browser_type']) && count($this->pObj->MOD_MENU['ts_browser_type']) > 1) { |
||
312 | $assigns['browserTypeDropdownMenu'] = BackendUtility::getDropdownMenu($this->pObj->id, 'SET[ts_browser_type]', $bType, $this->pObj->MOD_MENU['ts_browser_type']); |
||
313 | } |
||
314 | $assigns['hasTopLevelInObjectList'] = is_array($this->pObj->MOD_MENU['ts_browser_toplevel_' . $bType]) && count($this->pObj->MOD_MENU['ts_browser_toplevel_' . $bType]) > 1; |
||
315 | if (is_array($this->pObj->MOD_MENU['ts_browser_toplevel_' . $bType]) && count($this->pObj->MOD_MENU['ts_browser_toplevel_' . $bType]) > 1) { |
||
316 | $assigns['objectListDropdownMenu'] = BackendUtility::getDropdownMenu($this->pObj->id, 'SET[ts_browser_toplevel_' . $bType . ']', $this->pObj->MOD_SETTINGS['ts_browser_toplevel_' . $bType], $this->pObj->MOD_MENU['ts_browser_toplevel_' . $bType]); |
||
317 | } |
||
318 | |||
319 | $assigns['regexSearchCheckbox'] = BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_browser_regexsearch]', $this->pObj->MOD_SETTINGS['ts_browser_regexsearch'], '', '', 'id="checkTs_browser_regexsearch"'); |
||
320 | $assigns['postSearchField'] = $POST['search_field']; |
||
321 | $theKey = $this->pObj->MOD_SETTINGS['ts_browser_toplevel_' . $bType]; |
||
322 | if (!$theKey || !str_replace('-', '', $theKey)) { |
||
323 | $theKey = ''; |
||
324 | } |
||
325 | list($theSetup, $theSetupValue) = $this->templateService->ext_getSetup($theSetup, $this->pObj->MOD_SETTINGS['ts_browser_toplevel_' . $bType] ? $this->pObj->MOD_SETTINGS['ts_browser_toplevel_' . $bType] : ''); |
||
326 | $tree = $this->templateService->ext_getObjTree($theSetup, $theKey, '', '', $theSetupValue, $this->pObj->MOD_SETTINGS['ts_browser_alphaSort']); |
||
327 | $tree = $this->templateService->substituteCMarkers($tree); |
||
328 | $urlParameters = [ |
||
329 | 'id' => $this->pObj->id |
||
330 | ]; |
||
331 | /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */ |
||
332 | $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class); |
||
333 | $aHref = (string)$uriBuilder->buildUriFromRoute('web_ts', $urlParameters); |
||
334 | // Parser Errors: |
||
335 | $pEkey = $bType === 'setup' ? 'config' : 'constants'; |
||
336 | $assigns['hasParseErrors'] = !empty($this->templateService->parserErrors[$pEkey]); |
||
337 | if (!empty($this->templateService->parserErrors[$pEkey])) { |
||
338 | $assigns['showErrorDetailsUri'] = $aHref . '&SET[function]=TYPO3\\CMS\\Tstemplate\\Controller\\TemplateAnalyzerModuleFunctionController&template=all&SET[ts_analyzer_checkLinenum]=1#line-'; |
||
339 | $assigns['parseErrors'] = $this->templateService->parserErrors[$pEkey]; |
||
340 | } |
||
341 | |||
342 | if (isset($this->pObj->MOD_SETTINGS['ts_browser_TLKeys_' . $bType][$theKey])) { |
||
343 | $assigns['moduleUrlRemoveFromObjectList'] = $aHref . '&addKey[' . $theKey . ']=0&SET[ts_browser_toplevel_' . $bType . ']=0'; |
||
344 | } |
||
345 | |||
346 | $assigns['hasKeySelected'] = $theKey !== ''; |
||
347 | |||
348 | if ($theKey) { |
||
349 | $assigns['treeLabel'] = $theKey; |
||
350 | } else { |
||
351 | $assigns['rootLLKey'] = $bType === 'setup' ? 'setupRoot' : 'constantRoot'; |
||
352 | } |
||
353 | $assigns['tsTree'] = $tree; |
||
354 | |||
355 | // second row options |
||
356 | $assigns['isSetupAndCropLinesDisabled'] = $bType === 'setup' && !$this->pObj->MOD_SETTINGS['ts_browser_fixedLgd']; |
||
357 | $assigns['checkBoxShowComments'] = BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_browser_showComments]', $this->pObj->MOD_SETTINGS['ts_browser_showComments'], '', '', 'id="checkTs_browser_showComments"'); |
||
358 | $assigns['checkBoxAlphaSort'] = BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_browser_alphaSort]', $this->pObj->MOD_SETTINGS['ts_browser_alphaSort'], '', '', 'id="checkTs_browser_alphaSort"'); |
||
359 | $assigns['checkBoxCropLines'] = BackendUtility::getFuncCheck($this->pObj->id, 'SET[ts_browser_fixedLgd]', $this->pObj->MOD_SETTINGS['ts_browser_fixedLgd'], '', '', 'id="checkTs_browser_fixedLgd"'); |
||
360 | if ($bType === 'setup' && !$this->pObj->MOD_SETTINGS['ts_browser_fixedLgd']) { |
||
361 | $assigns['dropdownDisplayConstants'] = BackendUtility::getDropdownMenu($this->pObj->id, 'SET[ts_browser_const]', $this->pObj->MOD_SETTINGS['ts_browser_const'], $this->pObj->MOD_MENU['ts_browser_const']); |
||
362 | } |
||
363 | |||
364 | // Conditions: |
||
365 | $assigns['hasConditions'] = is_array($this->templateService->sections) && !empty($this->templateService->sections); |
||
366 | if (is_array($this->templateService->sections) && !empty($this->templateService->sections)) { |
||
367 | $tsConditions = []; |
||
368 | foreach ($this->templateService->sections as $key => $val) { |
||
369 | $tsConditions[] = [ |
||
370 | 'key' => $key, |
||
371 | 'value' => $val, |
||
372 | 'label' => $this->templateService->substituteCMarkers(htmlspecialchars($val)), |
||
373 | 'isSet' => $this->pObj->MOD_SETTINGS['tsbrowser_conditions'][$key] ? true : false |
||
374 | ]; |
||
375 | } |
||
376 | $assigns['tsConditions'] = $tsConditions; |
||
377 | } |
||
378 | // Ending section displayoptions |
||
379 | } |
||
380 | $this->getPageRenderer(); |
||
381 | $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip'); |
||
382 | $view = GeneralUtility::makeInstance(StandaloneView::class); |
||
383 | $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName( |
||
384 | 'EXT:tstemplate/Resources/Private/Templates/TemplateObjectBrowserModuleFunction.html' |
||
385 | )); |
||
386 | $view->assignMultiple($assigns); |
||
387 | |||
388 | return $view->render(); |
||
389 | } |
||
405 |