[TASK] Show hints about shortcuts and external pages in Page module 15/49715/5
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 1 Sep 2016 11:22:31 +0000 (13:22 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Thu, 6 Oct 2016 14:17:08 +0000 (16:17 +0200)
To improve the usability, pages of the type shortcut and external link
show additional information in the page module

Resolves: #77742
Releases: master
Change-Id: Ica5e2ecc017842bc6cca9bd347a59def2c7b6ad4
Reviewed-on: https://review.typo3.org/49715
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Tested-by: Michael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Łukasz Uznański
Tested-by: Łukasz Uznański
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/backend/Classes/Controller/PageLayoutController.php
typo3/sysext/backend/Resources/Private/Language/locallang_layout.xlf

index 8dff1e8..47a9931 100644 (file)
@@ -543,6 +543,9 @@ class PageLayoutController
         $content = '';
         $lang = $this->getLanguageService();
 
+        $view = GeneralUtility::makeInstance(StandaloneView::class);
+        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
+
         // If page is a folder
         if ($this->pageinfo['doktype'] == PageRepository::DOKTYPE_SYSFOLDER) {
             $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
@@ -552,8 +555,6 @@ class PageLayoutController
                 $title = $lang->getLL('goToListModule');
                 $message = '<p>' . $lang->getLL('goToListModuleMessage') . '</p>';
                 $message .= '<a class="btn btn-info" href="javascript:top.goToModule(\'web_list\',1);">' . $lang->getLL('goToListModule') . '</a>';
-                $view = GeneralUtility::makeInstance(StandaloneView::class);
-                $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
                 $view->assignMultiple([
                     'title' => $title,
                     'message' => $message,
@@ -561,6 +562,72 @@ class PageLayoutController
                 ]);
                 $content .= $view->render();
             }
+        } elseif ($this->pageinfo['doktype'] === PageRepository::DOKTYPE_SHORTCUT) {
+            $shortcutMode = (int)$this->pageinfo['shortcut_mode'];
+            $pageRepository = GeneralUtility::makeInstance(PageRepository::class);
+            $targetPage = [];
+
+            if ($this->pageinfo['shortcut'] || $shortcutMode) {
+                switch ($shortcutMode) {
+                    case PageRepository::SHORTCUT_MODE_NONE:
+                        $targetPage = $pageRepository->getPage($this->pageinfo['shortcut']);
+                        break;
+                    case PageRepository::SHORTCUT_MODE_FIRST_SUBPAGE:
+                        $targetPage = reset($pageRepository->getMenu($this->pageinfo['shortcut'] ?: $this->pageinfo['uid']));
+                        break;
+                    case PageRepository::SHORTCUT_MODE_PARENT_PAGE:
+                        $targetPage = $pageRepository->getPage($this->pageinfo['pid']);
+                        break;
+                }
+
+                $message = '';
+                if ($shortcutMode === PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) {
+                    $message .= sprintf($lang->getLL('pageIsRandomInternalLinkMessage'));
+                } else {
+                    $linkToPid = $this->local_linkThisScript(['id' => $targetPage['uid']]);
+                    $path = BackendUtility::getRecordPath($targetPage['uid'], $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW), 1000);
+                    $linkedPath = '<a href="' . $linkToPid . '">' . htmlspecialchars($path) . '</a>';
+                    $message .= sprintf($lang->getLL('pageIsInternalLinkMessage'), $linkedPath);
+                }
+
+                $message .= ' (' . htmlspecialchars($lang->sL(BackendUtility::getLabelFromItemlist('pages', 'shortcut_mode', $shortcutMode))) . ')';
+
+                $view->assignMultiple([
+                    'title' => $this->pageinfo['title'],
+                    'message' => $message,
+                    'state' => InfoboxViewHelper::STATE_INFO
+                ]);
+                $content .= $view->render();
+            } else {
+                if (empty($targetPage) && $shortcutMode !== PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) {
+                    $view->assignMultiple([
+                        'title' => $this->pageinfo['title'],
+                        'message' => $lang->getLL('pageIsMisconfiguredInternalLinkMessage'),
+                        'state' => InfoboxViewHelper::STATE_ERROR
+                    ]);
+                    $content .= $view->render();
+                }
+            }
+        } elseif ($this->pageinfo['doktype'] === PageRepository::DOKTYPE_LINK) {
+            if (empty($this->pageinfo['url'])) {
+                $view->assignMultiple([
+                    'title' => $this->pageinfo['title'],
+                    'message' => $lang->getLL('pageIsMisconfiguredExternalLinkMessage'),
+                    'state' => InfoboxViewHelper::STATE_ERROR
+                ]);
+                $content .= $view->render();
+            } else {
+                $externalUrl = htmlspecialchars(GeneralUtility::makeInstance(PageRepository::class)->getExtURL($this->pageinfo));
+                if ($externalUrl !== false) {
+                    $externalUrlHtml = '<a href="' . $externalUrl . '" target="_blank" rel="noopener">' . $externalUrl . '</a>';
+                    $view->assignMultiple([
+                        'title' => $this->pageinfo['title'],
+                        'message' => sprintf($lang->getLL('pageIsExternalLinkMessage'), $externalUrlHtml),
+                        'state' => InfoboxViewHelper::STATE_INFO
+                    ]);
+                    $content .= $view->render();
+                }
+            }
         }
         // If content from different pid is displayed
         if ($this->pageinfo['content_from_pid']) {
@@ -569,8 +636,6 @@ class PageLayoutController
             $title = BackendUtility::getRecordTitle('pages', $contentPage);
             $link = '<a href="' . $linkToPid . '">' . htmlspecialchars($title) . ' (PID ' . (int)$this->pageinfo['content_from_pid'] . ')</a>';
             $message = sprintf($lang->getLL('content_from_pid_title'), $link);
-            $view = GeneralUtility::makeInstance(StandaloneView::class);
-            $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
             $view->assignMultiple([
                 'title' => $title,
                 'message' => $message,
index ab85533..c61d9e4 100644 (file)
                        <trans-unit id="content_from_pid_title">
                                <source>Page uses content from this page: %s</source>
                        </trans-unit>
+                       <trans-unit id="pageIsExternalLinkMessage">
+                               <source>Page is a link to the following external URL: %s</source>
+                       </trans-unit>
+                       <trans-unit id="pageIsInternalLinkMessage">
+                               <source>Page is a link to the following page: %s</source>
+                       </trans-unit>
+                       <trans-unit id="pageIsRandomInternalLinkMessage">
+                               <source>Page is a link to a random page.</source>
+                       </trans-unit>
+                       <trans-unit id="pageIsMisconfiguredInternalLinkMessage">
+                               <source>Page is configured to be a link but there is actually no target defined.</source>
+                       </trans-unit>
+                       <trans-unit id="pageIsMisconfiguredExternalLinkMessage">
+                               <source>Page is configured to be an external link but there is actually no URL defined.</source>
+                       </trans-unit>
                        <trans-unit id="goToListModule">
                                <source>Go to list module</source>
                        </trans-unit>