[FEATURE] Let select() fetch records without translation parent 83/13083/6
authorBenjamin Mack <benni@typo3.org>
Thu, 26 Jul 2012 14:28:49 +0000 (16:28 +0200)
committerMarkus Klein <klein.t3@mfc-linz.at>
Sun, 13 Oct 2013 13:52:27 +0000 (15:52 +0200)
When you fetch records through the TypoScript object
"CONTENT" (or, let's say through ".select" in general),
you have an option called "languageField" in order
to fetch only records that match the current language.

What "select" does here, is that it fetches all records in
the default language ("0,-1") and then overlays them
with the records of the current language.

However, it's not possible to fetch the records that
don't have a localization parent.

The patch introduces a new option called
"includeRecordsWithoutDefaultTranslation" that also
checks for records with the languageField matching the
current language, where there is no translation parent
(l10n_parent = 0).

Change-Id: I48dc3a3b72a1dce515c5e5dd2278137888a1fe7f
Resolves: #24005
Releases: 6.2
Reviewed-on: https://review.typo3.org/13083
Reviewed-by: Alexander Opitz
Tested-by: Alexander Opitz
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php

index 42ad334..3aedad2 100644 (file)
@@ -7796,14 +7796,27 @@ class ContentObjectRenderer {
                        $query .= ' AND ' . $where;
                }
                if ($conf['languageField']) {
-                       if ($GLOBALS['TSFE']->sys_language_contentOL && $GLOBALS['TCA'][$table] && $GLOBALS['TCA'][$table]['ctrl']['languageField'] && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']) {
+                       // The sys_language record UID of the content of the page
+                       $sys_language_content = intval($GLOBALS['TSFE']->sys_language_content);
+
+                       if ($GLOBALS['TSFE']->sys_language_contentOL
+                               && isset($GLOBALS['TCA'][$table])
+                               && !empty($GLOBALS['TCA'][$table]['ctrl']['languageField'])
+                               && !empty($GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'])
+                       ) {
                                // Sys language content is set to zero/-1 - and it is expected that whatever routine processes the output will
                                // OVERLAY the records with localized versions!
-                               $sys_language_content = '0,-1';
+                               $languageQuery = $conf['languageField'] . ' IN (0,-1)';
+                               // Use this option to include records that don't have a default translation
+                               // (originalpointerfield is 0 and the language field contains the requested language)
+                               if (!empty($conf['includeRecordsWithoutDefaultTranslation'])) {
+                                       $languageQuery .= ' OR (' . $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] . ' = 0 AND ' .
+                                               $conf['languageField'] . ' = ' . $sys_language_content . ')';
+                               }
                        } else {
-                               $sys_language_content = intval($GLOBALS['TSFE']->sys_language_content);
+                               $languageQuery = $conf['languageField'] . ' = ' . $sys_language_content;
                        }
-                       $query .= ' AND ' . $conf['languageField'] . ' IN (' . $sys_language_content . ')';
+                       $query .= ' AND (' . $languageQuery . ')';
                }
                $andWhere = isset($conf['andWhere.']) ? trim($this->stdWrap($conf['andWhere'], $conf['andWhere.'])) : trim($conf['andWhere']);
                if ($andWhere) {