| Total Complexity | 107 |
| Total Lines | 1069 |
| 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 |
||
| 624 | { |
||
| 625 | $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu'); |
||
| 626 | $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip'); |
||
| 627 | $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Localization'); |
||
| 628 | $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/DragDrop'); |
||
| 629 | $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal'); |
||
| 630 | $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/Paste'); |
||
| 631 | $this->pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf'); |
||
| 632 | |||
| 633 | $tableOutput = ''; |
||
| 634 | $numberOfHiddenElements = 0; |
||
| 635 | |||
| 636 | if ($this->context instanceof PageLayoutContext) { |
||
| 637 | // Context may not be set, which happens if the page module is viewed by a user with no access to the |
||
| 638 | // current page, or if the ID parameter is malformed. In this case we do not resolve any backend layout |
||
| 639 | // or other page structure information and we do not render any "table output" for the module. |
||
| 640 | $backendLayout = $this->context->getBackendLayout(); |
||
| 641 | |||
| 642 | $configuration = $this->context->getDrawingConfiguration(); |
||
| 643 | $configuration->setDefaultLanguageBinding(!empty($this->modTSconfig['properties']['defLangBinding'])); |
||
| 644 | $configuration->setActiveColumns(GeneralUtility::trimExplode(',', $this->activeColPosList)); |
||
| 645 | $configuration->setShowHidden((bool)$this->MOD_SETTINGS['tt_content_showHidden']); |
||
| 646 | $configuration->setLanguageColumns($this->MOD_MENU['language']); |
||
| 647 | $configuration->setShowNewContentWizard(empty($this->modTSconfig['properties']['disableNewContentElementWizard'])); |
||
| 648 | $configuration->setSelectedLanguageId((int)$this->MOD_SETTINGS['language']); |
||
| 649 | if ($this->MOD_SETTINGS['function'] == 2) { |
||
| 650 | $configuration->setLanguageMode(true); |
||
| 651 | } |
||
| 652 | |||
| 653 | $numberOfHiddenElements = $this->getNumberOfHiddenElements($configuration->getLanguageColumns()); |
||
| 654 | |||
| 655 | $pageLayoutDrawer = $this->context->getBackendLayoutRenderer(); |
||
| 656 | |||
| 657 | $pageActionsCallback = null; |
||
| 658 | if ($this->context->isPageEditable()) { |
||
| 659 | $languageOverlayId = 0; |
||
| 660 | $pageLocalizationRecord = BackendUtility::getRecordLocalization('pages', $this->id, (int)$this->current_sys_language); |
||
| 661 | if (is_array($pageLocalizationRecord)) { |
||
| 662 | $pageLocalizationRecord = reset($pageLocalizationRecord); |
||
| 663 | } |
||
| 664 | if (!empty($pageLocalizationRecord['uid'])) { |
||
| 665 | $languageOverlayId = $pageLocalizationRecord['uid']; |
||
| 666 | } |
||
| 667 | $pageActionsCallback = 'function(PageActions) { |
||
| 668 | PageActions.setPageId(' . (int)$this->id . '); |
||
| 669 | PageActions.setLanguageOverlayId(' . $languageOverlayId . '); |
||
| 670 | }'; |
||
| 671 | } |
||
| 672 | $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/PageActions', $pageActionsCallback); |
||
| 673 | $tableOutput = $pageLayoutDrawer->drawContent(); |
||
| 674 | } |
||
| 675 | |||
| 676 | if ($this->getBackendUser()->check('tables_select', 'tt_content') && $numberOfHiddenElements > 0) { |
||
| 677 | // Toggle hidden ContentElements |
||
| 678 | $tableOutput .= ' |
||
| 679 | <div class="checkbox"> |
||
| 680 | <label for="checkTt_content_showHidden"> |
||
| 681 | <input type="checkbox" id="checkTt_content_showHidden" class="checkbox" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' /> |
||
| 682 | ' . htmlspecialchars($this->getLanguageService()->getLL('hiddenCE')) . ' (<span class="t3js-hidden-counter">' . $numberOfHiddenElements . '</span>) |
||
| 683 | </label> |
||
| 684 | </div>'; |
||
| 685 | } |
||
| 686 | |||
| 687 | // Init the content |
||
| 688 | $content = ''; |
||
| 689 | // Additional header content |
||
| 690 | foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'] ?? [] as $hook) { |
||
| 691 | $params = []; |
||
| 692 | $content .= GeneralUtility::callUserFunction($hook, $params, $this); |
||
| 693 | } |
||
| 694 | $content .= $tableOutput; |
||
| 695 | // Making search form: |
||
| 696 | $this->searchContent = $this->getSearchBox(); |
||
| 697 | if ($this->searchContent) { |
||
| 698 | $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ToggleSearchToolbox'); |
||
| 699 | $toggleSearchFormButton = $this->buttonBar->makeLinkButton() |
||
| 700 | ->setClasses('t3js-toggle-search-toolbox') |
||
| 701 | ->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.title.searchIcon')) |
||
| 702 | ->setIcon($this->iconFactory->getIcon('actions-search', Icon::SIZE_SMALL)) |
||
| 703 | ->setHref('#'); |
||
| 704 | $this->buttonBar->addButton($toggleSearchFormButton, ButtonBar::BUTTON_POSITION_LEFT, 4); |
||
| 705 | } |
||
| 706 | // Additional footer content |
||
| 707 | foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'] ?? [] as $hook) { |
||
| 708 | $params = []; |
||
| 709 | $content .= GeneralUtility::callUserFunction($hook, $params, $this); |
||
| 710 | } |
||
| 711 | return $content; |
||
| 712 | } |
||
| 713 | |||
| 714 | /*************************** |
||
| 715 | * |
||
| 716 | * Sub-content functions, rendering specific parts of the module content. |
||
| 717 | * |
||
| 718 | ***************************/ |
||
| 719 | /** |
||
| 720 | * This creates the buttons for the modules |
||
| 721 | * @param ServerRequestInterface $request |
||
| 722 | */ |
||
| 723 | protected function makeButtons(ServerRequestInterface $request): void |
||
| 724 | { |
||
| 725 | // Add CSH (Context Sensitive Help) icon to tool bar |
||
| 726 | $contextSensitiveHelpButton = $this->buttonBar->makeHelpButton() |
||
| 727 | ->setModuleName('_MOD_' . $this->moduleName) |
||
| 728 | ->setFieldName('columns_' . $this->MOD_SETTINGS['function']); |
||
| 729 | $this->buttonBar->addButton($contextSensitiveHelpButton); |
||
| 730 | $lang = $this->getLanguageService(); |
||
| 731 | // View page |
||
| 732 | $pageTsConfig = BackendUtility::getPagesTSconfig($this->id); |
||
| 733 | // Exclude sysfolders, spacers and recycler by default |
||
| 734 | $excludeDokTypes = [ |
||
| 735 | PageRepository::DOKTYPE_RECYCLER, |
||
| 736 | PageRepository::DOKTYPE_SYSFOLDER, |
||
| 737 | PageRepository::DOKTYPE_SPACER |
||
| 738 | ]; |
||
| 739 | // Custom override of values |
||
| 740 | if (isset($pageTsConfig['TCEMAIN.']['preview.']['disableButtonForDokType'])) { |
||
| 741 | $excludeDokTypes = GeneralUtility::intExplode( |
||
| 742 | ',', |
||
| 743 | $pageTsConfig['TCEMAIN.']['preview.']['disableButtonForDokType'], |
||
| 744 | true |
||
| 745 | ); |
||
| 746 | } |
||
| 747 | |||
| 748 | if ( |
||
| 749 | !in_array((int)$this->pageinfo['doktype'], $excludeDokTypes, true) |
||
| 750 | && !VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER) |
||
| 751 | ) { |
||
| 752 | $languageParameter = $this->current_sys_language ? ('&L=' . $this->current_sys_language) : ''; |
||
| 753 | $previewDataAttributes = PreviewUriBuilder::create((int)$this->pageinfo['uid']) |
||
| 754 | ->withRootLine(BackendUtility::BEgetRootLine($this->pageinfo['uid'])) |
||
| 755 | ->withAdditionalQueryParameters($languageParameter) |
||
| 756 | ->buildDispatcherDataAttributes(); |
||
| 757 | $viewButton = $this->buttonBar->makeLinkButton() |
||
| 758 | ->setDataAttributes($previewDataAttributes ?? []) |
||
| 759 | ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage')) |
||
| 760 | ->setIcon($this->iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL)) |
||
| 761 | ->setHref('#'); |
||
| 762 | |||
| 763 | $this->buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 3); |
||
| 764 | } |
||
| 765 | // Shortcut |
||
| 766 | $shortcutButton = $this->buttonBar->makeShortcutButton() |
||
| 767 | ->setModuleName($this->moduleName) |
||
| 768 | ->setDisplayName($this->getShortcutTitle()) |
||
| 769 | ->setArguments([ |
||
| 770 | 'route' => $request->getQueryParams()['route'], |
||
| 771 | 'id' => (int)$this->id, |
||
| 772 | 'SET' => [ |
||
| 773 | 'tt_content_showHidden' => (bool)$this->MOD_SETTINGS['tt_content_showHidden'], |
||
| 774 | 'function' => (int)$this->MOD_SETTINGS['function'], |
||
| 775 | 'language' => (int)$this->current_sys_language, |
||
| 776 | ] |
||
| 777 | ]); |
||
| 778 | $this->buttonBar->addButton($shortcutButton); |
||
| 779 | |||
| 780 | // Cache |
||
| 781 | $clearCacheButton = $this->buttonBar->makeLinkButton() |
||
| 782 | ->setHref('#') |
||
| 783 | ->setDataAttributes(['id' => $this->pageinfo['uid']]) |
||
| 784 | ->setClasses('t3js-clear-page-cache') |
||
| 785 | ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.clear_cache')) |
||
| 786 | ->setIcon($this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL)); |
||
| 787 | $this->buttonBar->addButton($clearCacheButton, ButtonBar::BUTTON_POSITION_RIGHT, 1); |
||
| 788 | |||
| 789 | // Edit page properties and page language overlay icons |
||
| 790 | if ($this->isPageEditable(0)) { |
||
| 791 | /** @var \TYPO3\CMS\Core\Http\NormalizedParams */ |
||
| 792 | $normalizedParams = $request->getAttribute('normalizedParams'); |
||
| 793 | // Edit localized pages only when one specific language is selected |
||
| 794 | if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) { |
||
| 795 | $localizationParentField = $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField']; |
||
| 796 | $languageField = $GLOBALS['TCA']['pages']['ctrl']['languageField']; |
||
| 797 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 798 | ->getQueryBuilderForTable('pages'); |
||
| 799 | $queryBuilder->getRestrictions() |
||
| 800 | ->removeAll() |
||
| 801 | ->add(GeneralUtility::makeInstance(DeletedRestriction::class)) |
||
| 802 | ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace)); |
||
| 803 | $overlayRecord = $queryBuilder |
||
| 804 | ->select('uid') |
||
| 805 | ->from('pages') |
||
| 806 | ->where( |
||
| 807 | $queryBuilder->expr()->eq( |
||
| 808 | $localizationParentField, |
||
| 809 | $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT) |
||
| 810 | ), |
||
| 811 | $queryBuilder->expr()->eq( |
||
| 812 | $languageField, |
||
| 813 | $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT) |
||
| 814 | ) |
||
| 815 | ) |
||
| 816 | ->setMaxResults(1) |
||
| 817 | ->execute() |
||
| 818 | ->fetch(); |
||
| 819 | BackendUtility::workspaceOL('pages', $overlayRecord, (int)$this->getBackendUser()->workspace); |
||
| 820 | // Edit button |
||
| 821 | $urlParameters = [ |
||
| 822 | 'edit' => [ |
||
| 823 | 'pages' => [ |
||
| 824 | $overlayRecord['uid'] => 'edit' |
||
| 825 | ] |
||
| 826 | ], |
||
| 827 | 'returnUrl' => $normalizedParams->getRequestUri(), |
||
| 828 | ]; |
||
| 829 | |||
| 830 | $url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters); |
||
| 831 | $editLanguageButton = $this->buttonBar->makeLinkButton() |
||
| 832 | ->setHref($url) |
||
| 833 | ->setTitle($lang->getLL('editPageLanguageOverlayProperties')) |
||
| 834 | ->setIcon($this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL)); |
||
| 835 | $this->buttonBar->addButton($editLanguageButton, ButtonBar::BUTTON_POSITION_LEFT, 3); |
||
| 836 | } |
||
| 837 | $urlParameters = [ |
||
| 838 | 'edit' => [ |
||
| 839 | 'pages' => [ |
||
| 840 | $this->id => 'edit' |
||
| 841 | ] |
||
| 842 | ], |
||
| 843 | 'returnUrl' => $normalizedParams->getRequestUri(), |
||
| 844 | ]; |
||
| 845 | $url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters); |
||
| 846 | $editPageButton = $this->buttonBar->makeLinkButton() |
||
| 847 | ->setHref($url) |
||
| 848 | ->setTitle($lang->getLL('editPageProperties')) |
||
| 849 | ->setIcon($this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)); |
||
| 850 | $this->buttonBar->addButton($editPageButton, ButtonBar::BUTTON_POSITION_LEFT, 3); |
||
| 851 | } |
||
| 852 | } |
||
| 853 | |||
| 854 | /******************************* |
||
| 855 | * |
||
| 856 | * Other functions |
||
| 857 | * |
||
| 858 | ******************************/ |
||
| 859 | /** |
||
| 860 | * Returns the number of hidden elements (including those hidden by start/end times) |
||
| 861 | * on the current page (for the current sys_language) |
||
| 862 | * |
||
| 863 | * @param array $languageColumns |
||
| 864 | * @return int |
||
| 865 | */ |
||
| 866 | protected function getNumberOfHiddenElements(array $languageColumns): int |
||
| 867 | { |
||
| 868 | $andWhere = []; |
||
| 869 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content'); |
||
| 870 | $queryBuilder->getRestrictions() |
||
| 871 | ->removeAll() |
||
| 872 | ->add(GeneralUtility::makeInstance(DeletedRestriction::class)) |
||
| 873 | ->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace)); |
||
| 874 | |||
| 875 | $queryBuilder |
||
| 876 | ->count('uid') |
||
| 877 | ->from('tt_content') |
||
| 878 | ->where( |
||
| 879 | $queryBuilder->expr()->eq( |
||
| 880 | 'pid', |
||
| 881 | $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT) |
||
| 882 | ) |
||
| 883 | ); |
||
| 884 | |||
| 885 | if (!empty($languageColumns)) { |
||
| 886 | // Multi-language view is active |
||
| 887 | if ($this->current_sys_language > 0) { |
||
| 888 | $queryBuilder->andWhere( |
||
| 889 | $queryBuilder->expr()->in( |
||
| 890 | 'sys_language_uid', |
||
| 891 | [0, $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)] |
||
| 892 | ) |
||
| 893 | ); |
||
| 894 | } |
||
| 895 | } else { |
||
| 896 | $queryBuilder->andWhere( |
||
| 897 | $queryBuilder->expr()->eq( |
||
| 898 | 'sys_language_uid', |
||
| 899 | $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT) |
||
| 900 | ) |
||
| 901 | ); |
||
| 902 | } |
||
| 903 | |||
| 904 | if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'])) { |
||
| 905 | $andWhere[] = $queryBuilder->expr()->neq( |
||
| 906 | 'hidden', |
||
| 907 | $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT) |
||
| 908 | ); |
||
| 909 | } |
||
| 910 | |||
| 911 | if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['starttime'])) { |
||
| 912 | $andWhere[] = $queryBuilder->expr()->andX( |
||
| 913 | $queryBuilder->expr()->neq( |
||
| 914 | 'starttime', |
||
| 915 | $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT) |
||
| 916 | ), |
||
| 917 | $queryBuilder->expr()->gt( |
||
| 918 | 'starttime', |
||
| 919 | $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT) |
||
| 920 | ) |
||
| 921 | ); |
||
| 922 | } |
||
| 923 | |||
| 924 | if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['endtime'])) { |
||
| 925 | $andWhere[] = $queryBuilder->expr()->andX( |
||
| 926 | $queryBuilder->expr()->neq( |
||
| 927 | 'endtime', |
||
| 928 | $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT) |
||
| 929 | ), |
||
| 930 | $queryBuilder->expr()->lte( |
||
| 931 | 'endtime', |
||
| 932 | $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT) |
||
| 933 | ) |
||
| 934 | ); |
||
| 935 | } |
||
| 936 | |||
| 937 | if (!empty($andWhere)) { |
||
| 938 | $queryBuilder->andWhere( |
||
| 939 | $queryBuilder->expr()->orX(...$andWhere) |
||
| 940 | ); |
||
| 941 | } |
||
| 942 | |||
| 943 | $count = $queryBuilder |
||
| 944 | ->execute() |
||
| 945 | ->fetchColumn(0); |
||
| 946 | |||
| 947 | return (int)$count; |
||
| 948 | } |
||
| 949 | |||
| 950 | /** |
||
| 951 | * Check if page can be edited by current user |
||
| 952 | * |
||
| 953 | * @param int $languageId |
||
| 954 | * @return bool |
||
| 955 | */ |
||
| 956 | protected function isPageEditable(int $languageId): bool |
||
| 957 | { |
||
| 958 | if ($this->getBackendUser()->isAdmin()) { |
||
| 959 | return true; |
||
| 960 | } |
||
| 961 | |||
| 962 | return !$this->pageinfo['editlock'] |
||
| 963 | && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::PAGE_EDIT) |
||
| 964 | && $this->getBackendUser()->checkLanguageAccess($languageId); |
||
| 965 | } |
||
| 966 | |||
| 967 | /** |
||
| 968 | * Check if content can be edited by current user |
||
| 969 | * |
||
| 970 | * @param int $languageId |
||
| 971 | * @return bool |
||
| 972 | */ |
||
| 973 | protected function isContentEditable(int $languageId): bool |
||
| 974 | { |
||
| 975 | if ($this->getBackendUser()->isAdmin()) { |
||
| 976 | return true; |
||
| 977 | } |
||
| 978 | |||
| 979 | return !$this->pageinfo['editlock'] |
||
| 980 | && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT) |
||
| 981 | && $this->getBackendUser()->checkLanguageAccess($languageId); |
||
| 982 | } |
||
| 983 | |||
| 984 | /** |
||
| 985 | * Returns LanguageService |
||
| 986 | * |
||
| 987 | * @return LanguageService |
||
| 988 | */ |
||
| 989 | protected function getLanguageService(): LanguageService |
||
| 990 | { |
||
| 991 | return $GLOBALS['LANG']; |
||
| 992 | } |
||
| 993 | |||
| 994 | /** |
||
| 995 | * Returns the current BE user. |
||
| 996 | * |
||
| 997 | * @return BackendUserAuthentication |
||
| 998 | */ |
||
| 999 | protected function getBackendUser(): BackendUserAuthentication |
||
| 1000 | { |
||
| 1001 | return $GLOBALS['BE_USER']; |
||
| 1002 | } |
||
| 1003 | |||
| 1004 | /** |
||
| 1005 | * Make the LanguageMenu |
||
| 1006 | */ |
||
| 1007 | protected function makeLanguageMenu(): void |
||
| 1023 | } |
||
| 1024 | } |
||
| 1025 | |||
| 1026 | /** |
||
| 1027 | * Returns the target page if visible |
||
| 1028 | * |
||
| 1029 | * @param array $targetPage |
||
| 1030 | * |
||
| 1031 | * @return array |
||
| 1032 | */ |
||
| 1033 | protected function getTargetPageIfVisible(array $targetPage): array |
||
| 1034 | { |
||
| 1035 | return !(bool)($targetPage['hidden'] ?? false) ? $targetPage : []; |
||
| 1036 | } |
||
| 1037 | |||
| 1038 | /** |
||
| 1039 | * Creates the search box |
||
| 1040 | * |
||
| 1041 | * @return string HTML for the search box |
||
| 1042 | */ |
||
| 1043 | protected function getSearchBox(): string |
||
| 1097 | </button> |
||
| 1098 | </div> |
||
| 1099 | </div> |
||
| 1100 | </div> |
||
| 1101 | </div> |
||
| 1102 | </div> |
||
| 1103 | </div> |
||
| 1104 | </form> |
||
| 1105 | </div>'; |
||
| 1106 | } |
||
| 1107 | |||
| 1108 | /** |
||
| 1109 | * Returns the shortcut title for the current page |
||
| 1110 | * |
||
| 1111 | * @return string |
||
| 1112 | */ |
||
| 1113 | protected function getShortcutTitle(): string |
||
| 1120 | ); |
||
| 1121 | } |
||
| 1122 | } |
||
| 1123 |