Skip to content

Commit

Permalink
[BUGFIX] Always fetch necessary fields for "record saved" notification
Browse files Browse the repository at this point in the history
Due to another couple of use cases, the necessary
fields to generate the record title, used in the
"record saved" notification in FormEngine, are now
always fetched, if not already present.

Additionally, it's now ensured that the "uid" is
always available, since it is necessary for
labels with foreign table lookups.

Resolves: #101964
Releases: main, 12.4
Change-Id: I933211f582e31c7af9fea909075420316a81a544
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81068
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
  • Loading branch information
o-ba committed Sep 20, 2023
1 parent 6d1a37b commit df37e6c
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions typo3/sysext/backend/Classes/Controller/EditDocumentController.php
Expand Up @@ -654,26 +654,29 @@ protected function processData(ModuleTemplate $view, ServerRequestInterface $req
if (!in_array($table . '.' . $uid, $erroneousRecords, true)) {
$realUidInPayload = ($tceSubstId = array_search($uid, $tce->substNEWwithIDs, true)) !== false ? $tceSubstId : $uid;
$row = $this->data[$table][$uid] ?? $this->data[$table][$realUidInPayload] ?? null;
if ($row !== null) {
if ($this->columnsOnly) {
// If label of the record is not available, fetch it from database
// This is the case when EditDocumentController is booted in single field mode (e.g. Template module > 'info/modify' > edit 'setup' field)
$labelArray = [$GLOBALS['TCA'][$table]['ctrl']['label'] ?? null];
$labelAltArray = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['label_alt'] ?? '', true);
$labelFields = array_unique(array_filter(array_merge($labelArray, $labelAltArray)));
foreach ($labelFields as $labelField) {
if (!isset($row[$labelField])) {
$tmpRecord = BackendUtility::getRecord($table, $uid, implode(',', $labelFields));
if ($tmpRecord !== null) {
$row = array_merge($row, $tmpRecord);
}
break;
}
if ($row === null) {
continue;
}
// Ensure, uid is always available to make labels with foreign table lookups possible
$row['uid'] ??= $realUidInPayload;
// If the label column of the record is not available, fetch it from database.
// This is the when EditDocumentController is booted in single field mode (e.g.
// Template module > 'info/modify' > edit 'setup' field) or in case the field is
// not in "showitem" or is set to readonly (e.g. "file" in sys_file_metadata).
$labelArray = [$GLOBALS['TCA'][$table]['ctrl']['label'] ?? null];
$labelAltArray = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['label_alt'] ?? '', true);
$labelFields = array_unique(array_filter(array_merge($labelArray, $labelAltArray)));
foreach ($labelFields as $labelField) {
if (!isset($row[$labelField])) {
$tmpRecord = BackendUtility::getRecord($table, $uid, implode(',', $labelFields));
if ($tmpRecord !== null) {
$row = array_merge($row, $tmpRecord);
}
break;
}
$recordTitle = GeneralUtility::fixed_lgd_cs(BackendUtility::getRecordTitle($table, $row), (int)$this->getBackendUser()->uc['titleLen']);
$messages[] = sprintf($this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf:notification.record_saved.message'), $recordTitle);
}
$recordTitle = GeneralUtility::fixed_lgd_cs(BackendUtility::getRecordTitle($table, $row), (int)$this->getBackendUser()->uc['titleLen']);
$messages[] = sprintf($this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf:notification.record_saved.message'), $recordTitle);
}
}

Expand Down

0 comments on commit df37e6c

Please sign in to comment.