Total Complexity | 109 |
Total Lines | 1073 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like PageLayoutController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PageLayoutController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
51 | class PageLayoutController |
||
52 | { |
||
53 | /** |
||
54 | * Page Id for which to make the listing |
||
55 | * |
||
56 | * @var int |
||
57 | * @internal |
||
58 | */ |
||
59 | public $id; |
||
60 | |||
61 | /** |
||
62 | * Module TSconfig |
||
63 | * |
||
64 | * @var array |
||
65 | */ |
||
66 | protected $modTSconfig = []; |
||
67 | |||
68 | /** |
||
69 | * Module shared TSconfig |
||
70 | * |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $modSharedTSconfig = []; |
||
74 | |||
75 | /** |
||
76 | * Current ids page record |
||
77 | * |
||
78 | * @var array|bool |
||
79 | * @internal |
||
80 | */ |
||
81 | public $pageinfo; |
||
82 | |||
83 | /** |
||
84 | * List of column-integers to edit. Is set from TSconfig, default is "1,0,2,3" |
||
85 | * |
||
86 | * @var string |
||
87 | */ |
||
88 | protected $colPosList; |
||
89 | |||
90 | /** |
||
91 | * Currently selected language for editing content elements |
||
92 | * |
||
93 | * @var int |
||
94 | */ |
||
95 | protected $current_sys_language; |
||
96 | |||
97 | /** |
||
98 | * Menu configuration |
||
99 | * |
||
100 | * @var array |
||
101 | */ |
||
102 | protected $MOD_MENU = []; |
||
103 | |||
104 | /** |
||
105 | * Module settings (session variable) |
||
106 | * |
||
107 | * @var array |
||
108 | * @internal |
||
109 | */ |
||
110 | public $MOD_SETTINGS = []; |
||
111 | |||
112 | /** |
||
113 | * List of column-integers accessible to the current BE user. |
||
114 | * Is set from TSconfig, default is $colPosList |
||
115 | * |
||
116 | * @var string |
||
117 | */ |
||
118 | protected $activeColPosList; |
||
119 | |||
120 | /** |
||
121 | * @var IconFactory |
||
122 | */ |
||
123 | protected $iconFactory; |
||
124 | |||
125 | /** |
||
126 | * The name of the module |
||
127 | * |
||
128 | * @var string |
||
129 | */ |
||
130 | protected $moduleName = 'web_layout'; |
||
131 | |||
132 | /** |
||
133 | * @var ModuleTemplate |
||
134 | */ |
||
135 | protected $moduleTemplate; |
||
136 | |||
137 | /** |
||
138 | * @var ButtonBar |
||
139 | */ |
||
140 | protected $buttonBar; |
||
141 | |||
142 | /** |
||
143 | * @var string |
||
144 | */ |
||
145 | protected $searchContent; |
||
146 | |||
147 | /** |
||
148 | * @var SiteLanguage[] |
||
149 | */ |
||
150 | protected $availableLanguages; |
||
151 | |||
152 | /** |
||
153 | * @var PageRenderer |
||
154 | */ |
||
155 | protected $pageRenderer; |
||
156 | |||
157 | /** |
||
158 | * @var UriBuilder |
||
159 | */ |
||
160 | protected $uriBuilder; |
||
161 | |||
162 | /** |
||
163 | * @var PageLayoutContext|null |
||
164 | */ |
||
165 | protected $context; |
||
166 | |||
167 | /** |
||
168 | * Injects the request object for the current request or subrequest |
||
169 | * As this controller goes only through the main() method, it is rather simple for now |
||
170 | * |
||
171 | * @param ServerRequestInterface $request the current request |
||
172 | * @return ResponseInterface the response with the content |
||
173 | */ |
||
174 | public function mainAction(ServerRequestInterface $request): ResponseInterface |
||
175 | { |
||
176 | $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class); |
||
177 | $this->pageRenderer = $this->moduleTemplate->getPageRenderer(); |
||
178 | $this->iconFactory = $this->moduleTemplate->getIconFactory(); |
||
179 | $this->uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); |
||
180 | $this->buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar(); |
||
181 | $this->getLanguageService()->includeLLFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf'); |
||
182 | // Setting module configuration / page select clause |
||
183 | $this->id = (int)($request->getParsedBody()['id'] ?? $request->getQueryParams()['id'] ?? 0); |
||
184 | |||
185 | // Load page info array |
||
186 | $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW)); |
||
187 | if ($this->pageinfo !== false) { |
||
188 | // If page info is not resolved, user has no access or the ID parameter was malformed. |
||
189 | $this->context = GeneralUtility::makeInstance( |
||
190 | PageLayoutContext::class, |
||
191 | $this->pageinfo, |
||
192 | GeneralUtility::makeInstance(BackendLayoutView::class)->getBackendLayoutForPage($this->id) |
||
193 | ); |
||
194 | } |
||
195 | |||
196 | /** @var SiteInterface $currentSite */ |
||
197 | $currentSite = $request->getAttribute('site'); |
||
198 | $this->availableLanguages = $currentSite->getAvailableLanguages($this->getBackendUser(), false, $this->id); |
||
199 | // initialize page/be_user TSconfig settings |
||
200 | $pageTsConfig = BackendUtility::getPagesTSconfig($this->id); |
||
201 | $this->modSharedTSconfig['properties'] = $pageTsConfig['mod.']['SHARED.'] ?? []; |
||
202 | $this->modTSconfig['properties'] = $pageTsConfig['mod.']['web_layout.'] ?? []; |
||
203 | |||
204 | // Initialize menu |
||
205 | $this->menuConfig($request); |
||
206 | // Setting sys language from session var |
||
207 | $this->current_sys_language = (int)$this->MOD_SETTINGS['language']; |
||
208 | |||
209 | $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Recordlist/ClearCache'); |
||
210 | |||
211 | $this->main($request); |
||
212 | return new HtmlResponse($this->moduleTemplate->renderContent()); |
||
213 | } |
||
214 | |||
215 | /** |
||
216 | * Initialize menu array |
||
217 | * @param ServerRequestInterface $request |
||
218 | */ |
||
219 | protected function menuConfig(ServerRequestInterface $request): void |
||
220 | { |
||
221 | // MENU-ITEMS: |
||
222 | $this->MOD_MENU = [ |
||
223 | 'tt_content_showHidden' => '', |
||
224 | 'function' => [ |
||
225 | 1 => $this->getLanguageService()->getLL('m_function_1'), |
||
226 | 2 => $this->getLanguageService()->getLL('m_function_2') |
||
227 | ], |
||
228 | 'language' => [ |
||
229 | 0 => $this->getLanguageService()->getLL('m_default') |
||
230 | ] |
||
231 | ]; |
||
232 | |||
233 | // First, select all localized page records on the current page. |
||
234 | // Each represents a possibility for a language on the page. Add these to language selector. |
||
235 | if ($this->id) { |
||
236 | // Compile language data for pid != 0 only. The language drop-down is not shown on pid 0 |
||
237 | // since pid 0 can't be localized. |
||
238 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); |
||
239 | $queryBuilder->getRestrictions()->removeAll() |
||
240 | ->add(GeneralUtility::makeInstance(DeletedRestriction::class)) |
||
241 | ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace)); |
||
242 | $statement = $queryBuilder->select('uid', $GLOBALS['TCA']['pages']['ctrl']['languageField']) |
||
243 | ->from('pages') |
||
244 | ->where( |
||
245 | $queryBuilder->expr()->eq( |
||
246 | $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'], |
||
247 | $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT) |
||
248 | ) |
||
249 | )->execute(); |
||
250 | while ($pageTranslation = $statement->fetch()) { |
||
251 | $languageId = $pageTranslation[$GLOBALS['TCA']['pages']['ctrl']['languageField']]; |
||
252 | if (isset($this->availableLanguages[$languageId])) { |
||
253 | $this->MOD_MENU['language'][$languageId] = $this->availableLanguages[$languageId]->getTitle(); |
||
254 | } |
||
255 | } |
||
256 | // Override the label |
||
257 | if (isset($this->availableLanguages[0])) { |
||
258 | $this->MOD_MENU['language'][0] = $this->availableLanguages[0]->getTitle(); |
||
259 | } |
||
260 | } |
||
261 | // Initialize the available actions |
||
262 | $actions = $this->initActions(); |
||
263 | // Clean up settings |
||
264 | $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, $request->getParsedBody()['SET'] ?? $request->getQueryParams()['SET'] ?? [], $this->moduleName); |
||
265 | // For all elements to be shown in draft workspaces & to also show hidden elements by default if user hasn't disabled the option |
||
266 | if ($this->getBackendUser()->workspace != 0 |
||
267 | || !isset($this->MOD_SETTINGS['tt_content_showHidden']) |
||
268 | || $this->MOD_SETTINGS['tt_content_showHidden'] !== '0' |
||
269 | ) { |
||
270 | $this->MOD_SETTINGS['tt_content_showHidden'] = 1; |
||
271 | } |
||
272 | // Make action menu from available actions |
||
273 | $this->makeActionMenu($actions); |
||
274 | } |
||
275 | |||
276 | /** |
||
277 | * Initializes the available actions this module provides |
||
278 | * |
||
279 | * @return array the available actions |
||
280 | */ |
||
281 | protected function initActions(): array |
||
282 | { |
||
283 | $actions = [ |
||
284 | 1 => $this->getLanguageService()->getLL('m_function_1') |
||
285 | ]; |
||
286 | // Find if there are ANY languages at all (and if not, do not show the language option from function menu). |
||
287 | if (count($this->availableLanguages) > 1) { |
||
288 | $actions[2] = $this->getLanguageService()->getLL('m_function_2'); |
||
289 | } |
||
290 | $this->makeLanguageMenu(); |
||
291 | // Page / user TSconfig blinding of menu-items |
||
292 | $blindActions = $this->modTSconfig['properties']['menu.']['functions.'] ?? []; |
||
293 | foreach ($blindActions as $key => $value) { |
||
294 | if (!$value && array_key_exists($key, $actions)) { |
||
295 | unset($actions[$key]); |
||
296 | } |
||
297 | } |
||
298 | |||
299 | return $actions; |
||
300 | } |
||
301 | |||
302 | /** |
||
303 | * This creates the dropdown menu with the different actions this module is able to provide. |
||
304 | * For now they are Columns and Languages. |
||
305 | * |
||
306 | * @param array $actions array with the available actions |
||
307 | */ |
||
308 | protected function makeActionMenu(array $actions): void |
||
309 | { |
||
310 | $actionMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu(); |
||
311 | $actionMenu->setIdentifier('actionMenu'); |
||
312 | $actionMenu->setLabel(''); |
||
313 | |||
314 | $defaultKey = null; |
||
315 | $foundDefaultKey = false; |
||
316 | foreach ($actions as $key => $action) { |
||
317 | $menuItem = $actionMenu |
||
318 | ->makeMenuItem() |
||
319 | ->setTitle($action) |
||
320 | ->setHref((string)$this->uriBuilder->buildUriFromRoute($this->moduleName) . '&id=' . $this->id . '&SET[function]=' . $key); |
||
321 | |||
322 | if (!$foundDefaultKey) { |
||
323 | $defaultKey = $key; |
||
324 | $foundDefaultKey = true; |
||
325 | } |
||
326 | if ((int)$this->MOD_SETTINGS['function'] === $key) { |
||
327 | $menuItem->setActive(true); |
||
328 | $defaultKey = null; |
||
329 | } |
||
330 | $actionMenu->addMenuItem($menuItem); |
||
331 | } |
||
332 | if (isset($defaultKey)) { |
||
333 | $this->MOD_SETTINGS['function'] = $defaultKey; |
||
334 | } |
||
335 | $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($actionMenu); |
||
336 | } |
||
337 | |||
338 | /** |
||
339 | * Generate the flashmessages for current pid |
||
340 | * |
||
341 | * @return string HTML content with flashmessages |
||
342 | */ |
||
343 | protected function getHeaderFlashMessagesForCurrentPid(): string |
||
344 | { |
||
345 | $content = ''; |
||
346 | $lang = $this->getLanguageService(); |
||
347 | |||
348 | $view = GeneralUtility::makeInstance(StandaloneView::class); |
||
349 | $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html')); |
||
350 | |||
351 | // If page is a folder |
||
352 | if ($this->pageinfo['doktype'] == PageRepository::DOKTYPE_SYSFOLDER) { |
||
353 | $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class); |
||
354 | $moduleLoader->load($GLOBALS['TBE_MODULES']); |
||
355 | $modules = $moduleLoader->modules; |
||
356 | if (is_array($modules['web']['sub']['list'])) { |
||
357 | $title = $lang->getLL('goToListModule'); |
||
358 | $message = '<p>' . $lang->getLL('goToListModuleMessage') . '</p>'; |
||
359 | $message .= '<a class="btn btn-info" href="javascript:top.goToModule(\'web_list\');">' . $lang->getLL('goToListModule') . '</a>'; |
||
360 | $view->assignMultiple([ |
||
361 | 'title' => $title, |
||
362 | 'message' => $message, |
||
363 | 'state' => InfoboxViewHelper::STATE_INFO |
||
364 | ]); |
||
365 | $content .= $view->render(); |
||
366 | } |
||
367 | } elseif ($this->pageinfo['doktype'] === PageRepository::DOKTYPE_SHORTCUT) { |
||
368 | $shortcutMode = (int)$this->pageinfo['shortcut_mode']; |
||
369 | $pageRepository = GeneralUtility::makeInstance(PageRepository::class); |
||
370 | $targetPage = []; |
||
371 | $message = ''; |
||
372 | $state = InfoboxViewHelper::STATE_ERROR; |
||
373 | |||
374 | if ($shortcutMode || $this->pageinfo['shortcut']) { |
||
375 | switch ($shortcutMode) { |
||
376 | case PageRepository::SHORTCUT_MODE_NONE: |
||
377 | $targetPage = $this->getTargetPageIfVisible($pageRepository->getPage($this->pageinfo['shortcut'])); |
||
378 | $message .= $targetPage === [] ? $lang->getLL('pageIsMisconfiguredOrNotAccessibleInternalLinkMessage') : ''; |
||
379 | break; |
||
380 | case PageRepository::SHORTCUT_MODE_FIRST_SUBPAGE: |
||
381 | $menuOfPages = $pageRepository->getMenu($this->pageinfo['uid'], '*', 'sorting', 'AND hidden = 0'); |
||
382 | $targetPage = reset($menuOfPages) ?: []; |
||
383 | $message .= $targetPage === [] ? $lang->getLL('pageIsMisconfiguredFirstSubpageMessage') : ''; |
||
384 | break; |
||
385 | case PageRepository::SHORTCUT_MODE_PARENT_PAGE: |
||
386 | $targetPage = $this->getTargetPageIfVisible($pageRepository->getPage($this->pageinfo['pid'])); |
||
387 | $message .= $targetPage === [] ? $lang->getLL('pageIsMisconfiguredParentPageMessage') : ''; |
||
388 | break; |
||
389 | case PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE: |
||
390 | $possibleTargetPages = $pageRepository->getMenu($this->pageinfo['uid'], '*', 'sorting', 'AND hidden = 0'); |
||
391 | if ($possibleTargetPages === []) { |
||
392 | $message .= $lang->getLL('pageIsMisconfiguredOrNotAccessibleRandomInternalLinkMessage'); |
||
393 | break; |
||
394 | } |
||
395 | $message = $lang->getLL('pageIsRandomInternalLinkMessage'); |
||
396 | $state = InfoboxViewHelper::STATE_INFO; |
||
397 | break; |
||
398 | } |
||
399 | $message = htmlspecialchars($message); |
||
400 | if ($targetPage !== [] && $shortcutMode !== PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) { |
||
401 | $linkToPid = GeneralUtility::linkThisScript(['id' => $targetPage['uid']]); |
||
402 | $path = BackendUtility::getRecordPath($targetPage['uid'], $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW), 1000); |
||
403 | $linkedPath = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($path) . '</a>'; |
||
|
|||
404 | $message .= sprintf(htmlspecialchars($lang->getLL('pageIsInternalLinkMessage')), $linkedPath); |
||
405 | $message .= ' (' . htmlspecialchars($lang->sL(BackendUtility::getLabelFromItemlist('pages', 'shortcut_mode', (string)$shortcutMode))) . ')'; |
||
406 | $state = InfoboxViewHelper::STATE_INFO; |
||
407 | } |
||
408 | } else { |
||
409 | $message = htmlspecialchars($lang->getLL('pageIsMisconfiguredInternalLinkMessage')); |
||
410 | $state = InfoboxViewHelper::STATE_ERROR; |
||
411 | } |
||
412 | |||
413 | $view->assignMultiple([ |
||
414 | 'title' => $this->pageinfo['title'], |
||
415 | 'message' => $message, |
||
416 | 'state' => $state |
||
417 | ]); |
||
418 | $content .= $view->render(); |
||
419 | } elseif ($this->pageinfo['doktype'] === PageRepository::DOKTYPE_LINK) { |
||
420 | if (empty($this->pageinfo['url'])) { |
||
421 | $view->assignMultiple([ |
||
422 | 'title' => $this->pageinfo['title'], |
||
423 | 'message' => $lang->getLL('pageIsMisconfiguredExternalLinkMessage'), |
||
424 | 'state' => InfoboxViewHelper::STATE_ERROR |
||
425 | ]); |
||
426 | $content .= $view->render(); |
||
427 | } else { |
||
428 | $externalUrl = GeneralUtility::makeInstance(PageRepository::class)->getExtURL($this->pageinfo); |
||
429 | if (is_string($externalUrl)) { |
||
430 | $externalUrl = htmlspecialchars($externalUrl); |
||
431 | $externalUrlHtml = '<a href="' . $externalUrl . '" target="_blank" rel="noreferrer">' . $externalUrl . '</a>'; |
||
432 | $view->assignMultiple([ |
||
433 | 'title' => $this->pageinfo['title'], |
||
434 | 'message' => sprintf($lang->getLL('pageIsExternalLinkMessage'), $externalUrlHtml), |
||
435 | 'state' => InfoboxViewHelper::STATE_INFO |
||
436 | ]); |
||
437 | $content .= $view->render(); |
||
438 | } |
||
439 | } |
||
440 | } |
||
441 | // If content from different pid is displayed |
||
442 | if ($this->pageinfo['content_from_pid']) { |
||
443 | $contentPage = (array)BackendUtility::getRecord('pages', (int)$this->pageinfo['content_from_pid']); |
||
444 | $linkToPid = GeneralUtility::linkThisScript(['id' => $this->pageinfo['content_from_pid']]); |
||
445 | $title = BackendUtility::getRecordTitle('pages', $contentPage); |
||
446 | $link = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$this->pageinfo['content_from_pid'] . ')</a>'; |
||
447 | $message = sprintf($lang->getLL('content_from_pid_title'), $link); |
||
448 | $view->assignMultiple([ |
||
449 | 'title' => $title, |
||
450 | 'message' => $message, |
||
451 | 'state' => InfoboxViewHelper::STATE_INFO |
||
452 | ]); |
||
453 | $content .= $view->render(); |
||
454 | } else { |
||
455 | $links = $this->getPageLinksWhereContentIsAlsoShownOn($this->pageinfo['uid']); |
||
456 | if (!empty($links)) { |
||
457 | $message = sprintf($lang->getLL('content_on_pid_title'), $links); |
||
458 | $view->assignMultiple([ |
||
459 | 'title' => '', |
||
460 | 'message' => $message, |
||
461 | 'state' => InfoboxViewHelper::STATE_INFO |
||
462 | ]); |
||
463 | $content .= $view->render(); |
||
464 | } |
||
465 | } |
||
466 | return $content; |
||
467 | } |
||
468 | |||
469 | /** |
||
470 | * Get all pages with links where the content of a page $pageId is also shown on |
||
471 | * |
||
472 | * @param int $pageId |
||
473 | * @return string |
||
474 | */ |
||
475 | protected function getPageLinksWhereContentIsAlsoShownOn($pageId): string |
||
496 | } |
||
497 | |||
498 | /** |
||
499 | * @return string $title |
||
500 | */ |
||
501 | protected function getLocalizedPageTitle(): string |
||
530 | } |
||
531 | |||
532 | /** |
||
533 | * Main function. |
||
534 | * Creates some general objects and calls other functions for the main rendering of module content. |
||
535 | * |
||
536 | * @param ServerRequestInterface $request |
||
537 | */ |
||
538 | protected function main(ServerRequestInterface $request): void |
||
616 | } |
||
617 | |||
618 | /** |
||
619 | * Rendering content |
||
620 | * |
||
621 | * @return string |
||
622 | */ |
||
623 | protected function renderContent(): string |
||
714 | } |
||
715 | |||
716 | /*************************** |
||
717 | * |
||
718 | * Sub-content functions, rendering specific parts of the module content. |
||
719 | * |
||
720 | ***************************/ |
||
721 | /** |
||
722 | * This creates the buttons for the modules |
||
723 | * @param ServerRequestInterface $request |
||
724 | */ |
||
725 | protected function makeButtons(ServerRequestInterface $request): void |
||
726 | { |
||
727 | // Add CSH (Context Sensitive Help) icon to tool bar |
||
728 | $contextSensitiveHelpButton = $this->buttonBar->makeHelpButton() |
||
729 | ->setModuleName('_MOD_' . $this->moduleName) |
||
730 | ->setFieldName('columns_' . $this->MOD_SETTINGS['function']); |
||
731 | $this->buttonBar->addButton($contextSensitiveHelpButton); |
||
732 | $lang = $this->getLanguageService(); |
||
733 | // View page |
||
734 | $pageTsConfig = BackendUtility::getPagesTSconfig($this->id); |
||
735 | // Exclude sysfolders, spacers and recycler by default |
||
736 | $excludeDokTypes = [ |
||
737 | PageRepository::DOKTYPE_RECYCLER, |
||
738 | PageRepository::DOKTYPE_SYSFOLDER, |
||
739 | PageRepository::DOKTYPE_SPACER |
||
740 | ]; |
||
741 | // Custom override of values |
||
742 | if (isset($pageTsConfig['TCEMAIN.']['preview.']['disableButtonForDokType'])) { |
||
743 | $excludeDokTypes = GeneralUtility::intExplode( |
||
744 | ',', |
||
745 | $pageTsConfig['TCEMAIN.']['preview.']['disableButtonForDokType'], |
||
746 | true |
||
747 | ); |
||
748 | } |
||
749 | |||
750 | if ( |
||
751 | !in_array((int)$this->pageinfo['doktype'], $excludeDokTypes, true) |
||
752 | && !VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER) |
||
753 | ) { |
||
754 | $languageParameter = $this->current_sys_language ? ('&L=' . $this->current_sys_language) : ''; |
||
755 | $previewDataAttributes = PreviewUriBuilder::create((int)$this->pageinfo['uid']) |
||
756 | ->withRootLine(BackendUtility::BEgetRootLine($this->pageinfo['uid'])) |
||
757 | ->withAdditionalQueryParameters($languageParameter) |
||
758 | ->buildDispatcherDataAttributes(); |
||
759 | $viewButton = $this->buttonBar->makeLinkButton() |
||
760 | ->setDataAttributes($previewDataAttributes ?? []) |
||
761 | ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage')) |
||
762 | ->setIcon($this->iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL)) |
||
763 | ->setHref('#'); |
||
764 | |||
765 | $this->buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 3); |
||
766 | } |
||
767 | // Shortcut |
||
768 | $shortcutButton = $this->buttonBar->makeShortcutButton() |
||
769 | ->setModuleName($this->moduleName) |
||
770 | ->setDisplayName($this->getShortcutTitle()) |
||
771 | ->setArguments([ |
||
772 | 'route' => $request->getQueryParams()['route'], |
||
773 | 'id' => (int)$this->id, |
||
774 | 'SET' => [ |
||
775 | 'tt_content_showHidden' => (bool)$this->MOD_SETTINGS['tt_content_showHidden'], |
||
776 | 'function' => (int)$this->MOD_SETTINGS['function'], |
||
777 | 'language' => (int)$this->current_sys_language, |
||
778 | ] |
||
779 | ]); |
||
780 | $this->buttonBar->addButton($shortcutButton); |
||
781 | |||
782 | // Cache |
||
783 | $clearCacheButton = $this->buttonBar->makeLinkButton() |
||
784 | ->setHref('#') |
||
785 | ->setDataAttributes(['id' => $this->pageinfo['uid']]) |
||
786 | ->setClasses('t3js-clear-page-cache') |
||
787 | ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.clear_cache')) |
||
788 | ->setIcon($this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL)); |
||
789 | $this->buttonBar->addButton($clearCacheButton, ButtonBar::BUTTON_POSITION_RIGHT, 1); |
||
790 | |||
791 | if (empty($this->modTSconfig['properties']['disableIconToolbar'])) { |
||
792 | // Edit page properties and page language overlay icons |
||
793 | if ($this->isPageEditable(0)) { |
||
794 | /** @var \TYPO3\CMS\Core\Http\NormalizedParams */ |
||
795 | $normalizedParams = $request->getAttribute('normalizedParams'); |
||
796 | // Edit localized pages only when one specific language is selected |
||
797 | if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) { |
||
798 | $localizationParentField = $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField']; |
||
799 | $languageField = $GLOBALS['TCA']['pages']['ctrl']['languageField']; |
||
800 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
801 | ->getQueryBuilderForTable('pages'); |
||
802 | $queryBuilder->getRestrictions() |
||
803 | ->removeAll() |
||
804 | ->add(GeneralUtility::makeInstance(DeletedRestriction::class)) |
||
805 | ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace)); |
||
806 | $overlayRecord = $queryBuilder |
||
807 | ->select('uid') |
||
808 | ->from('pages') |
||
809 | ->where( |
||
810 | $queryBuilder->expr()->eq( |
||
811 | $localizationParentField, |
||
812 | $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT) |
||
813 | ), |
||
814 | $queryBuilder->expr()->eq( |
||
815 | $languageField, |
||
816 | $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT) |
||
817 | ) |
||
818 | ) |
||
819 | ->setMaxResults(1) |
||
820 | ->execute() |
||
821 | ->fetch(); |
||
822 | BackendUtility::workspaceOL('pages', $overlayRecord, (int)$this->getBackendUser()->workspace); |
||
823 | // Edit button |
||
824 | $urlParameters = [ |
||
825 | 'edit' => [ |
||
826 | 'pages' => [ |
||
827 | $overlayRecord['uid'] => 'edit' |
||
828 | ] |
||
829 | ], |
||
830 | 'returnUrl' => $normalizedParams->getRequestUri(), |
||
831 | ]; |
||
832 | |||
833 | $url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters); |
||
834 | $editLanguageButton = $this->buttonBar->makeLinkButton() |
||
835 | ->setHref($url) |
||
836 | ->setTitle($lang->getLL('editPageLanguageOverlayProperties')) |
||
837 | ->setIcon($this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL)); |
||
838 | $this->buttonBar->addButton($editLanguageButton, ButtonBar::BUTTON_POSITION_LEFT, 3); |
||
839 | } |
||
840 | $urlParameters = [ |
||
841 | 'edit' => [ |
||
842 | 'pages' => [ |
||
843 | $this->id => 'edit' |
||
844 | ] |
||
845 | ], |
||
846 | 'returnUrl' => $normalizedParams->getRequestUri(), |
||
847 | ]; |
||
848 | $url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters); |
||
849 | $editPageButton = $this->buttonBar->makeLinkButton() |
||
850 | ->setHref($url) |
||
851 | ->setTitle($lang->getLL('editPageProperties')) |
||
852 | ->setIcon($this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)); |
||
853 | $this->buttonBar->addButton($editPageButton, ButtonBar::BUTTON_POSITION_LEFT, 3); |
||
854 | } |
||
855 | } |
||
856 | } |
||
857 | |||
858 | /******************************* |
||
859 | * |
||
860 | * Other functions |
||
861 | * |
||
862 | ******************************/ |
||
863 | /** |
||
864 | * Returns the number of hidden elements (including those hidden by start/end times) |
||
865 | * on the current page (for the current sys_language) |
||
866 | * |
||
867 | * @param array $languageColumns |
||
868 | * @return int |
||
869 | */ |
||
870 | protected function getNumberOfHiddenElements(array $languageColumns): int |
||
871 | { |
||
872 | $andWhere = []; |
||
873 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content'); |
||
874 | $queryBuilder->getRestrictions() |
||
875 | ->removeAll() |
||
876 | ->add(GeneralUtility::makeInstance(DeletedRestriction::class)) |
||
877 | ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace)); |
||
878 | |||
879 | $queryBuilder |
||
880 | ->count('uid') |
||
881 | ->from('tt_content') |
||
882 | ->where( |
||
883 | $queryBuilder->expr()->eq( |
||
884 | 'pid', |
||
885 | $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT) |
||
886 | ) |
||
887 | ); |
||
888 | |||
889 | if (!empty($languageColumns)) { |
||
890 | // Multi-language view is active |
||
891 | if ($this->current_sys_language > 0) { |
||
892 | $queryBuilder->andWhere( |
||
893 | $queryBuilder->expr()->in( |
||
894 | 'sys_language_uid', |
||
895 | [0, $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)] |
||
896 | ) |
||
897 | ); |
||
898 | } |
||
899 | } else { |
||
900 | $queryBuilder->andWhere( |
||
901 | $queryBuilder->expr()->eq( |
||
902 | 'sys_language_uid', |
||
903 | $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT) |
||
904 | ) |
||
905 | ); |
||
906 | } |
||
907 | |||
908 | if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'])) { |
||
909 | $andWhere[] = $queryBuilder->expr()->neq( |
||
910 | 'hidden', |
||
911 | $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT) |
||
912 | ); |
||
913 | } |
||
914 | |||
915 | if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['starttime'])) { |
||
916 | $andWhere[] = $queryBuilder->expr()->andX( |
||
917 | $queryBuilder->expr()->neq( |
||
918 | 'starttime', |
||
919 | $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT) |
||
920 | ), |
||
921 | $queryBuilder->expr()->gt( |
||
922 | 'starttime', |
||
923 | $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT) |
||
924 | ) |
||
925 | ); |
||
926 | } |
||
927 | |||
928 | if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['endtime'])) { |
||
929 | $andWhere[] = $queryBuilder->expr()->andX( |
||
930 | $queryBuilder->expr()->neq( |
||
931 | 'endtime', |
||
932 | $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT) |
||
933 | ), |
||
934 | $queryBuilder->expr()->lte( |
||
935 | 'endtime', |
||
936 | $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT) |
||
937 | ) |
||
938 | ); |
||
939 | } |
||
940 | |||
941 | if (!empty($andWhere)) { |
||
942 | $queryBuilder->andWhere( |
||
943 | $queryBuilder->expr()->orX(...$andWhere) |
||
944 | ); |
||
945 | } |
||
946 | |||
947 | $count = $queryBuilder |
||
948 | ->execute() |
||
949 | ->fetchColumn(0); |
||
950 | |||
951 | return (int)$count; |
||
952 | } |
||
953 | |||
954 | /** |
||
955 | * Check if page can be edited by current user |
||
956 | * |
||
957 | * @param int $languageId |
||
958 | * @return bool |
||
959 | */ |
||
960 | protected function isPageEditable(int $languageId): bool |
||
961 | { |
||
962 | if ($this->getBackendUser()->isAdmin()) { |
||
963 | return true; |
||
964 | } |
||
965 | |||
966 | return !$this->pageinfo['editlock'] |
||
967 | && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::PAGE_EDIT) |
||
968 | && $this->getBackendUser()->checkLanguageAccess($languageId); |
||
969 | } |
||
970 | |||
971 | /** |
||
972 | * Check if content can be edited by current user |
||
973 | * |
||
974 | * @param int $languageId |
||
975 | * @return bool |
||
976 | */ |
||
977 | protected function isContentEditable(int $languageId): bool |
||
978 | { |
||
979 | if ($this->getBackendUser()->isAdmin()) { |
||
980 | return true; |
||
981 | } |
||
982 | |||
983 | return !$this->pageinfo['editlock'] |
||
984 | && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT) |
||
985 | && $this->getBackendUser()->checkLanguageAccess($languageId); |
||
986 | } |
||
987 | |||
988 | /** |
||
989 | * Returns LanguageService |
||
990 | * |
||
991 | * @return LanguageService |
||
992 | */ |
||
993 | protected function getLanguageService(): LanguageService |
||
994 | { |
||
995 | return $GLOBALS['LANG']; |
||
996 | } |
||
997 | |||
998 | /** |
||
999 | * Returns the current BE user. |
||
1000 | * |
||
1001 | * @return BackendUserAuthentication |
||
1002 | */ |
||
1003 | protected function getBackendUser(): BackendUserAuthentication |
||
1004 | { |
||
1005 | return $GLOBALS['BE_USER']; |
||
1006 | } |
||
1007 | |||
1008 | /** |
||
1009 | * Make the LanguageMenu |
||
1010 | */ |
||
1011 | protected function makeLanguageMenu(): void |
||
1027 | } |
||
1028 | } |
||
1029 | |||
1030 | /** |
||
1031 | * Returns the target page if visible |
||
1032 | * |
||
1033 | * @param array $targetPage |
||
1034 | * |
||
1035 | * @return array |
||
1036 | */ |
||
1037 | protected function getTargetPageIfVisible(array $targetPage): array |
||
1038 | { |
||
1039 | return !(bool)($targetPage['hidden'] ?? false) ? $targetPage : []; |
||
1040 | } |
||
1041 | |||
1042 | /** |
||
1043 | * Creates the search box |
||
1044 | * |
||
1045 | * @return string HTML for the search box |
||
1046 | */ |
||
1047 | protected function getSearchBox(): string |
||
1101 | </button> |
||
1102 | </div> |
||
1103 | </div> |
||
1104 | </div> |
||
1105 | </div> |
||
1106 | </div> |
||
1107 | </div> |
||
1108 | </form> |
||
1109 | </div>'; |
||
1110 | } |
||
1111 | |||
1112 | /** |
||
1113 | * Returns the shortcut title for the current page |
||
1114 | * |
||
1115 | * @return string |
||
1116 | */ |
||
1117 | protected function getShortcutTitle(): string |
||
1124 | ); |
||
1125 | } |
||
1126 | } |
||
1127 |