Commit 10eb394b authored by Oliver Bartsch's avatar Oliver Bartsch Committed by Frank Nägler
Browse files

[TASK] Make infobox for shortcut pages more helpful

Add proper information for the user about the target page.

In case the target page doesn't exist or is not accessible
in the frontend, the infobox in the page module now states this out.

Resolves: #89121
Releases: master, 9.5
Change-Id: Ie4d5b208028fa960e34dec64c546a2e5ebb1de05
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61710


Tested-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Frank Nägler's avatarFrank Nägler <frank.naegler@typo3.org>
Tested-by: default avatarTYPO3com <noreply@typo3.com>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Frank Nägler's avatarFrank Nägler <frank.naegler@typo3.org>
parent e4a3762a
......@@ -482,48 +482,54 @@ class PageLayoutController
$shortcutMode = (int)$this->pageinfo['shortcut_mode'];
$pageRepository = GeneralUtility::makeInstance(PageRepository::class);
$targetPage = [];
$message = '';
$state = InfoboxViewHelper::STATE_ERROR;
if ($this->pageinfo['shortcut'] || $shortcutMode) {
if ($shortcutMode || $this->pageinfo['shortcut']) {
switch ($shortcutMode) {
case PageRepository::SHORTCUT_MODE_NONE:
$targetPage = $pageRepository->getPage($this->pageinfo['shortcut']);
$targetPage = $this->getTargetPageIfVisible($pageRepository->getPage($this->pageinfo['shortcut']));
$message .= $targetPage === [] ? $lang->getLL('pageIsMisconfiguredOrNotAccessibleInternalLinkMessage') : '';
break;
case PageRepository::SHORTCUT_MODE_FIRST_SUBPAGE:
$targetPage = reset($pageRepository->getMenu($this->pageinfo['shortcut'] ?: $this->pageinfo['uid']));
$menuOfPages = $pageRepository->getMenu($this->pageinfo['uid'], '*', 'sorting', 'AND hidden = 0');
$targetPage = reset($menuOfPages) ?: [];
$message .= $targetPage === [] ? $lang->getLL('pageIsMisconfiguredFirstSubpageMessage') : '';
break;
case PageRepository::SHORTCUT_MODE_PARENT_PAGE:
$targetPage = $pageRepository->getPage($this->pageinfo['pid']);
$targetPage = $this->getTargetPageIfVisible($pageRepository->getPage($this->pageinfo['pid']));
$message .= $targetPage === [] ? $lang->getLL('pageIsMisconfiguredParentPageMessage') : '';
break;
case PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE:
$possibleTargetPages = $pageRepository->getMenu($this->pageinfo['uid'], '*', 'sorting', 'AND hidden = 0');
if ($possibleTargetPages === []) {
$message .= $lang->getLL('pageIsMisconfiguredOrNotAccessibleRandomInternalLinkMessage');
break;
}
$message = $lang->getLL('pageIsRandomInternalLinkMessage');
$state = InfoboxViewHelper::STATE_INFO;
break;
}
$message = '';
if ($shortcutMode === PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) {
$message .= sprintf($lang->getLL('pageIsRandomInternalLinkMessage'));
} else {
$message = htmlspecialchars($message);
if ($targetPage !== [] && $shortcutMode !== PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) {
$linkToPid = $this->local_linkThisScript(['id' => $targetPage['uid']]);
$path = BackendUtility::getRecordPath($targetPage['uid'], $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW), 1000);
$linkedPath = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($path) . '</a>';
$message .= sprintf($lang->getLL('pageIsInternalLinkMessage'), $linkedPath);
$message .= sprintf(htmlspecialchars($lang->getLL('pageIsInternalLinkMessage')), $linkedPath);
$message .= ' (' . htmlspecialchars($lang->sL(BackendUtility::getLabelFromItemlist('pages', 'shortcut_mode', $shortcutMode))) . ')';
$state = InfoboxViewHelper::STATE_INFO;
}
$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();
}
$message = htmlspecialchars($lang->getLL('pageIsMisconfiguredInternalLinkMessage'));
$state = InfoboxViewHelper::STATE_ERROR;
}
$view->assignMultiple([
'title' => $this->pageinfo['title'],
'message' => $message,
'state' => $state
]);
$content .= $view->render();
} elseif ($this->pageinfo['doktype'] === PageRepository::DOKTYPE_LINK) {
if (empty($this->pageinfo['url'])) {
$view->assignMultiple([
......@@ -1233,4 +1239,16 @@ class PageLayoutController
return (bool)$count;
}
/**
* Returns the target page if visible
*
* @param array $targetPage
*
* @return array
*/
protected function getTargetPageIfVisible(array $targetPage): array
{
return !(bool)($targetPage['hidden'] ?? false) ? $targetPage : [];
}
}
......@@ -280,10 +280,22 @@
<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>
<source>Page is a link to a random subpage.</source>
</trans-unit>
<trans-unit id="pageIsMisconfiguredInternalLinkMessage">
<source>Page is configured to be a link but there is actually no target defined.</source>
<source>Page is configured to be a link but there is actually no valid target defined.</source>
</trans-unit>
<trans-unit id="pageIsMisconfiguredOrNotAccessibleInternalLinkMessage">
<source>Page is configured to be a link but there is actually no target defined which is accessible in the frontend.</source>
</trans-unit>
<trans-unit id="pageIsMisconfiguredOrNotAccessibleRandomInternalLinkMessage">
<source>Page is configured to be a link to a random subpage but there is actually no subpage which is accessible in the frontend.</source>
</trans-unit>
<trans-unit id="pageIsMisconfiguredFirstSubpageMessage">
<source>Page is configured to be a link to the first subpage but there is actually no such page accessible in the frontend.</source>
</trans-unit>
<trans-unit id="pageIsMisconfiguredParentPageMessage">
<source>Page is configured to be a link to the parent page but there is actually no such page accessible in the frontend.</source>
</trans-unit>
<trans-unit id="pageIsMisconfiguredExternalLinkMessage">
<source>Page is configured to be an external link but there is actually no URL defined.</source>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment