Commit 3b3321ba authored by Oliver Bartsch's avatar Oliver Bartsch
Browse files

[BUGFIX] Check whether tt_content parent page is accessible

Both, DatabaseRecordList as well as the ContextMenu feature the
"Show" button to preview a content element on its parent page.
However, in case the parent page is a "no view doktype" (e.g. sys
folder), those buttons lead to a 404 error.

This is now fixed by properly checking whether a content elements'
parent page can be viewed. If not, the button is no longer shown.

Resolves: #93718
Releases: master, 10.4
Change-Id: I2ad48ee7e44d06f569496c4bed2bbd172791b86c
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69959

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
parent 678dfccb
......@@ -19,6 +19,7 @@ namespace TYPO3\CMS\Backend\ContextMenu\ItemProviders;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Routing\UnableToLinkToPageException;
use TYPO3\CMS\Core\Type\Bitmask\JsConfirmation;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
......@@ -496,7 +497,7 @@ class RecordProvider extends AbstractProvider
*/
protected function canBeViewed(): bool
{
return $this->table === 'tt_content';
return $this->table === 'tt_content' && $this->parentPageCanBeViewed();
}
/**
......@@ -719,6 +720,26 @@ class RecordProvider extends AbstractProvider
&& (int)($this->record['uid'] ?? 0) === (int)$this->backendUser->user[$this->backendUser->userid_column];
}
/**
* Check whether the elements' parent page can be viewed
*
* @return bool
*/
protected function parentPageCanBeViewed(): bool
{
if (!isset($this->pageRecord['uid']) || !($this->pageRecord['doktype'] ?? false)) {
// In case parent page record is invalid, the element can not be viewed
return false;
}
// Finally, we check whether the parent page has a "no view doktype" assigned
return !in_array((int)$this->pageRecord['doktype'], [
PageRepository::DOKTYPE_SPACER,
PageRepository::DOKTYPE_SYSFOLDER,
PageRepository::DOKTYPE_RECYCLER
], true);
}
/**
* @return string
*/
......
......@@ -1422,9 +1422,16 @@ class DatabaseRecordList
// "Show" link (only pages and tt_content elements)
$tsConfig = BackendUtility::getPagesTSconfig($this->id)['mod.']['web_list.'] ?? [];
if (
($table === 'pages' && !in_array($row['doktype'] ?? null, $this->getNoViewWithDokTypes($tsConfig)))
|| $table === 'tt_content'
if ((
$table === 'pages'
&& isset($row['doktype'])
&& !in_array((int)$row['doktype'], $this->getNoViewWithDokTypes($tsConfig), true)
)
|| (
$table === 'tt_content'
&& isset($this->pageRow['doktype'])
&& !in_array((int)$this->pageRow['doktype'], $this->getNoViewWithDokTypes($tsConfig), true)
)
) {
if (!$isDeletePlaceHolder) {
$attributes = $this->getPreviewUriBuilder($table, $row)->serializeDispatcherAttributes();
......@@ -3371,9 +3378,10 @@ class DatabaseRecordList
protected function getNoViewWithDokTypes(array $tsConfig): array
{
if (isset($tsConfig['noViewWithDokTypes'])) {
$noViewDokTypes = GeneralUtility::trimExplode(',', $tsConfig['noViewWithDokTypes'], true);
$noViewDokTypes = GeneralUtility::intExplode(',', $tsConfig['noViewWithDokTypes'], true);
} else {
$noViewDokTypes = [
PageRepository::DOKTYPE_SPACER,
PageRepository::DOKTYPE_SYSFOLDER,
PageRepository::DOKTYPE_RECYCLER
];
......
Markdown is supported
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