Issue Feature Closed

#59833levelmedia translation fallback

Tizian Schmidlin 06/24/14, 09:01 updated 03/02/16, 12:27

Description

Hello there,

I recently run into a use case that was not covered by the standard TYPO3 features: translation fallback for levelmedia.

Explanation: we set up a new field for pages that is used to set a banner on the page. This banner may change according to the current page language (since banner may contain text in different languages). Now the customer didn’t have the time to replace all the banners on time, so we needed a fallback to the standard translation.

Sadly, this wasn’t covered by levelmedia yet, also the l10n_mode 'mergeIfNotBlank' didn’t do the trick, so I developed the following patch:

in TYPO3 4.5.x: typo3/sysext/cms/tslib/class.tslib_content.php:5261
in TYPO3 6.2.x: typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php:5426

case 'levelfield':
    $keyP = t3lib_div::trimExplode(',', $key);
    $nkey = $this->getKey($keyP[0], $GLOBALS['TSFE']->tmpl->rootLine);
    $rootLine = $GLOBALS['TSFE']->tmpl->rootLine;
    /** cab st: 2014-06-23: add an additional parameter for levelfield so you can take the value from the
     * original page data. If there wasn't any, check the other levels for values. As soon as a value is found, we
     * break the loop.
     */
    if($keyP[3] == 'from_original') {

        for($i = $nkey; $i >= 0; $i--) {
            if(empty($rootLine[$i][$keyP[1]])) {
                // try to get the original
                $newRow = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
                    '*',
                    'pages',
                    'uid = ' . $rootLine[$i]['uid']
                );

                if(!empty($newRow[$keyP[1]])) {
                    $rootLine[$i][$keyP[1]] = $newRow[$keyP[1]];
                    break;
                }                                    
            } else {
                // we already are on a superior level that has content, so no untranslation needed
                break;
            }
        }
    }
    $retVal = $this->rootLineValue($nkey, $keyP[1], strtolower($keyP[2]) == 'slide', $rootLine);
    /** cab st end */
break;

This patch is completely backwards compatible since you have to add a parameter to the levelfield after slide.

Best Regards

Tizian

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.