Skip to content

Instantly share code, notes, and snippets.

@a-r-m-i-n
Last active February 22, 2018 19:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-r-m-i-n/80272ad9af8a341785f20cbf36a1b1b2 to your computer and use it in GitHub Desktop.
Save a-r-m-i-n/80272ad9af8a341785f20cbf36a1b1b2 to your computer and use it in GitHub Desktop.
TYPO3 CMS TypoScript Condition to check for existing translation of current page

Usage

[userFunc = \Vendorname\Extension\UserConditions\user_translationExistsNot()] && [globalVar = GP:L > 0]
    # Add canonical tag
    # and/or display a notice, that the current page is not translated yet and the original contents are displayed
[global]

Install

  • put the user conditons (two php files) to EXT:extension/Classes/UserConditions/
  • update php namespace
  • Include the files in ext_localconf.php:
    $extensionPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY);
    
    // User Conditions
    require_once($extensionPath . 'Classes/UserConditions/user_translationExists.php');
    require_once($extensionPath . 'Classes/UserConditions/user_translationExistsNot.php');
<?php
namespace Vendorname\Extension\UserConditions;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
/**
* Checks if the current page in frontend has a translation.
*
* Usage:
* [userFunc = \Vendorname\Extension\UserConditions\user_translationExists()] && [globalVar = GP:L > 0]
*
* @return bool Returns TRUE if the current page has been translated
*/
function user_translationExists()
{
if (TYPO3_MODE !== 'FE' || GeneralUtility::_GP('eID')) {
return null;
}
/** @var $contentObjectRenderer ContentObjectRenderer */
$contentObjectRenderer = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer');
$sysLanguageUid = (int) GeneralUtility::_GP('L');
$pageUid = (int) $GLOBALS['TSFE']->id;
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'uid',
'pages_language_overlay',
'pid = ' . $pageUid . ' AND sys_language_uid = ' . $sysLanguageUid .
$contentObjectRenderer->enableFields('pages_language_overlay')
);
return (bool) $GLOBALS['TYPO3_DB']->sql_num_rows($res);
}
<?php
namespace Vendorname\Extension\UserConditions;
/**
* Checks if the current page in frontend has NOT a translation.
*
* Usage:
* [userFunc = \Vendorname\Extension\UserConditions\user_translationExistsNot()] && [globalVar = GP:L > 0]
*
* @return bool Returns TRUE if the current page has been NOT translated
*/
function user_translationExistsNot()
{
return !user_translationExists();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment