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