Commit 79809796 authored by Oliver Bartsch's avatar Oliver Bartsch
Browse files

[BUGFIX] Properly handle shortcuts for creating new records

When creating bookmarks to the "new" view in FormEngine,
those bookmark previously did not show up in the toolbar list,
because the parent page access check failed.

This is now fixed by also resolving the parent page for
new record bookmarks properly.

Additionally the shortcut title for those use cases does
now match the title, displayed in FormEngine.

Resolves: #97655
Releases: main, 11.5
Change-Id: If62391bffe4126c746b6c5650d1aa9d0821f2960
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74691


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Jochen's avatarJochen <rothjochen@gmail.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Jochen's avatarJochen <rothjochen@gmail.com>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
parent 4bc86d92
......@@ -392,7 +392,7 @@ class ShortcutRepository
$shortcut['type'] = 'new';
}
if (substr((string)$shortcut['recordid'], -1) === ',') {
if (str_ends_with((string)$shortcut['recordid'], ',')) {
$shortcut['recordid'] = substr((string)$shortcut['recordid'], 0, -1);
}
} else {
......@@ -435,17 +435,24 @@ class ShortcutRepository
}
} else {
if ($moduleName === 'record_edit' && isset($shortcut['table'], $shortcut['recordid'])) {
// Check if user is allowed to edit the requested record
// Check if user is allowed to modify the requested record
if (!$backendUser->check('tables_modify', $shortcut['table'])) {
continue;
}
$record = BackendUtility::getRecord($shortcut['table'], (int)$shortcut['recordid']);
// Check if requested record exists
if ($record === null || $record === []) {
continue;
if ($shortcut['type'] === 'edit'
|| ($shortcut['type'] === 'new' && (int)$shortcut['recordid'] < 0)
) {
$record = BackendUtility::getRecord($shortcut['table'], abs((int)$shortcut['recordid']));
// Check if requested record exists
if ($record === null || $record === []) {
continue;
}
// Store the page id of the record in question
$pageId = ($shortcut['table'] === 'pages' ? (int)($record['uid'] ?? 0) : (int)($record['pid'] ?? 0));
} elseif ($shortcut['type'] === 'new' && (int)$shortcut['recordid'] > 0) {
// If type is new and "recordid" is positive, it references the current page
$pageId = (int)$shortcut['recordid'];
}
// Store the page id of the record in question
$pageId = ($shortcut['table'] === 'pages' ? (int)($record['uid'] ?? 0) : (int)($record['pid']));
} else {
// In case this is no record edit shortcut, treat a possible "id" as page id
$pageId = (int)($arguments['id'] ?? 0);
......
......@@ -2284,6 +2284,42 @@ class EditDocumentController
$action = (string)($queryParameters['edit'][$table][$identifier] ?? '');
if ($action === 'new') {
if ($table === 'pages') {
return sprintf(
$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.createNewPage'),
$tableTitle
);
}
$identifier = (int)$identifier;
if ($identifier === 0) {
return sprintf(
$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.createNewRecordRootLevel'),
$tableTitle
);
}
$pageRecord = null;
if ($identifier < 0) {
$parentRecord = BackendUtility::getRecord($table, abs($identifier));
if ($parentRecord['pid'] ?? false) {
$pageRecord = BackendUtility::getRecord('pages', (int)($parentRecord['pid']), 'title');
}
} else {
$pageRecord = BackendUtility::getRecord('pages', $identifier, 'title');
}
if ($pageRecord !== null) {
$pageTitle = BackendUtility::getRecordTitle('pages', $pageRecord);
if ($pageTitle !== '') {
return sprintf(
$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.createNewRecord'),
$tableTitle,
$pageTitle
);
}
}
return $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.createNew') . ' ' . $tableTitle;
}
......
......@@ -2,9 +2,10 @@
,"uid","userid","description","sc_group","route","arguments"
,1,1,"Recordlist",1,"web_list","{""id"":123,""GET"":{""clipBoard"":1}}"
,2,1,"Edit Content",1,"record_edit","{""edit"":{""tt_content"":{""113"":""edit""}}}"
,3,1,"Page Layout - Group 2",2,"web_layout","{""id"":""123"",""SET"":{""tt_content_showHidden"":""1"",""function"":""1"",""language"":""0""}}"
,4,1,"Invalid route identifier",1,"web_proc","{""id"":""123""}"
,5,2,"Wrong user",1,"web_layout","{""id"":""123""}"
,6,1,,1,"web_layout","{""id"":""123""}"
,7,1,"Recordlist of id 111",0,"web_list","{""id"":111,""GET"":{""clipBoard"":1}}"
,8,1,"Shortcut",0,"record_edit","{""edit"":{""pages"":{""112"":""edit""}}}"
,3,1,"Create Content",1,"record_edit","{""edit"":{""tt_content"":{""117"":""new""}}}"
,4,1,"Page Layout - Group 2",2,"web_layout","{""id"":""123"",""SET"":{""tt_content_showHidden"":""1"",""function"":""1"",""language"":""0""}}"
,5,1,"Invalid route identifier",1,"web_proc","{""id"":""123""}"
,6,2,"Wrong user",1,"web_layout","{""id"":""123""}"
,7,1,,1,"web_layout","{""id"":""123""}"
,8,1,"Recordlist of id 111",0,"web_list","{""id"":111,""GET"":{""clipBoard"":1}}"
,9,1,"Shortcut",0,"record_edit","{""edit"":{""pages"":{""112"":""edit""}}}"
......@@ -2,10 +2,11 @@
,"uid","userid","description","sc_group","route","arguments"
,1,1,"Recordlist",1,"web_list","{""id"":123,""GET"":{""clipBoard"":1}}"
,2,1,"Edit Content",1,"record_edit","{""edit"":{""tt_content"":{""113"":""edit""}}}"
,3,1,"Page Layout - Group 2",2,"web_layout","{""id"":""123"",""SET"":{""tt_content_showHidden"":""1"",""function"":""1"",""language"":""0""}}"
,4,1,"Invalid route identifier",1,"web_proc","{""id"":""123""}"
,5,2,"Wrong user",1,"web_layout","{""id"":""123""}"
,6,1,,1,"web_layout","{""id"":""123""}"
,3,1,"Create Content",1,"record_edit","{""edit"":{""tt_content"":{""117"":""new""}}}"
,4,1,"Page Layout - Group 2",2,"web_layout","{""id"":""123"",""SET"":{""tt_content_showHidden"":""1"",""function"":""1"",""language"":""0""}}"
,5,1,"Invalid route identifier",1,"web_proc","{""id"":""123""}"
,6,2,"Wrong user",1,"web_layout","{""id"":""123""}"
,7,1,,1,"web_layout","{""id"":""123""}"
"tt_content",,,,,,
,"uid","pid","hidden","deleted","starttime","endtime"
,113,321,0,0,0,0
......@@ -151,7 +151,16 @@ class ShortcutRepositoryTest extends FunctionalTestCase
'icon' => 'data-identifier="mimetypes-x-content-text"',
'href' => '/typo3/record/edit?token=%s&edit%5Btt_content%5D%5B113%5D=edit',
],
6 => [
3 => [
'table' => 'tt_content',
'recordid' => 117,
'groupLabel' => null,
'type' => 'new',
'label' => 'Create Content',
'icon' => 'data-identifier="mimetypes-x-content-text"',
'href' => '/typo3/record/edit?token=%s&edit%5Btt_content%5D%5B117%5D=new',
],
7 => [
'table' => null,
'recordid' => null,
'groupLabel' => null,
......@@ -163,7 +172,7 @@ class ShortcutRepositoryTest extends FunctionalTestCase
];
$shortcuts = $this->subject->getShortcutsByGroup(1);
self::assertCount(3, $shortcuts);
self::assertCount(count($expected), $shortcuts);
foreach ($shortcuts as $shortcut) {
$id = (int)$shortcut['raw']['uid'];
......
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