Created
November 23, 2020 13:52
-
-
Save smichaelsen/f5d425b84db7007a512eff0a26247939 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/typo3/sysext/backend/Classes/Utility/BackendUtility.php | |
+++ b/typo3/sysext/backend/Classes/Utility/BackendUtility.php | |
@@ -2989,6 +2989,31 @@ | |
} | |
/** | |
+ * Creates a link to create a record translation on demand and directly edit it | |
+ * | |
+ * @param string $table | |
+ * @param int $defaultLanguageRecordUid | |
+ * @param int $targetLanguageUid | |
+ * @param string|null $returnUrl | |
+ * @return string | |
+ */ | |
+ public static function getLinkToCreateRecordTranslation(string $table, int $defaultLanguageRecordUid, int $targetLanguageUid, string $returnUrl = null): string | |
+ { | |
+ $redirectUrlParams = [ | |
+ 'justLocalized' => $table . ':' . $defaultLanguageRecordUid . ':' . $targetLanguageUid, | |
+ ]; | |
+ if ($returnUrl !== null) { | |
+ $redirectUrlParams['returnUrl'] = $returnUrl; | |
+ } | |
+ $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); | |
+ $redirectUrl = $uriBuilder->buildUriFromRoute('record_edit'); | |
+ return self::getLinkToDataHandlerAction( | |
+ '&cmd[' . $table . '][' . $defaultLanguageRecordUid . '][localize]=' . $targetLanguageUid, | |
+ $redirectUrl | |
+ ); | |
+ } | |
+ | |
+ /** | |
* Returns a JavaScript string (for an onClick handler) which will load the EditDocumentController script that shows the form for editing of the record(s) you have send as params. | |
* REMEMBER to always htmlspecialchar() content in href-properties to ampersands get converted to entities (XHTML requirement and XSS precaution) | |
* | |
--- a/typo3/sysext/backend/Classes/Controller/EditDocumentController.php | |
+++ b/typo3/sysext/backend/Classes/Controller/EditDocumentController.php | |
@@ -2112,7 +2112,7 @@ | |
$redirectUrl | |
); | |
} else { | |
- $addOption = false; | |
+ $href = BackendUtility::getLinkToCreateRecordTranslation($table, $rowsByLang[0]['uid'], $lang['uid'], $this->retUrl); | |
} | |
} else { | |
$params = [ | |
--- a/typo3/sysext/backend/Classes/Form/Container/InlineRecordContainer.php | |
+++ b/typo3/sysext/backend/Classes/Form/Container/InlineRecordContainer.php | |
@@ -22,6 +22,7 @@ | |
use TYPO3\CMS\Backend\Routing\UriBuilder; | |
use TYPO3\CMS\Backend\Utility\BackendUtility; | |
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; | |
+use TYPO3\CMS\Core\Database\Connection; | |
use TYPO3\CMS\Core\Database\ConnectionPool; | |
use TYPO3\CMS\Core\Imaging\Icon; | |
use TYPO3\CMS\Core\Imaging\IconFactory; | |
@@ -533,34 +534,44 @@ | |
} | |
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) | |
->getQueryBuilderForTable('sys_file_metadata'); | |
- $recordInDatabase = $queryBuilder | |
- ->select('uid') | |
+ $result = $queryBuilder | |
+ ->select('uid', 'sys_language_uid') | |
->from('sys_file_metadata') | |
->where( | |
$queryBuilder->expr()->eq( | |
'file', | |
$queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT) | |
), | |
- $queryBuilder->expr()->eq( | |
+ $queryBuilder->expr()->in( | |
'sys_language_uid', | |
- $queryBuilder->createNamedParameter($sys_language_uid, \PDO::PARAM_INT) | |
+ $queryBuilder->createNamedParameter([0, $sys_language_uid], Connection::PARAM_INT_ARRAY) | |
) | |
) | |
- ->setMaxResults(1) | |
- ->execute() | |
- ->fetch(); | |
- if (!empty($recordInDatabase)) { | |
+ ->execute(); | |
+ $recordsInDatabaseByLanguage = []; | |
+ while ($row = $result->fetch()) { | |
+ $recordsInDatabaseByLanguage[$row['sys_language_uid']] = $row; | |
+ } | |
+ if (empty($recordsInDatabaseByLanguage[$sys_language_uid])) { | |
+ // create translation on demand | |
+ $url = BackendUtility::getLinkToCreateRecordTranslation( | |
+ 'sys_file_metadata', | |
+ (int)$recordsInDatabaseByLanguage[0]['uid'], | |
+ $sys_language_uid, | |
+ $this->data['returnUrl'] | |
+ ); | |
+ } else { | |
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); | |
$url = (string)$uriBuilder->buildUriFromRoute('record_edit', [ | |
- 'edit[sys_file_metadata][' . (int)$recordInDatabase['uid'] . ']' => 'edit', | |
+ 'edit[sys_file_metadata][' . (int)$recordsInDatabaseByLanguage[$sys_language_uid]['uid'] . ']' => 'edit', | |
'returnUrl' => $this->data['returnUrl'] | |
]); | |
- $title = $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.editMetadata'); | |
- $cells['edit'] = ' | |
- <a class="btn btn-default" href="' . htmlspecialchars($url) . '" title="' . htmlspecialchars($title) . '"> | |
- ' . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . ' | |
- </a>'; | |
- } | |
+ } | |
+ $title = $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.editMetadata'); | |
+ $cells['edit'] = ' | |
+ <a class="btn btn-default" href="' . htmlspecialchars($url) . '" title="' . htmlspecialchars($title) . '"> | |
+ ' . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . ' | |
+ </a>'; | |
} | |
// "Delete" link: | |
if ($enabledControls['delete'] && ($isPagesTable && $localCalcPerms & Permission::PAGE_DELETE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment