Skip to content

Instantly share code, notes, and snippets.

@Tuurlijk
Last active February 1, 2017 12:36
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 Tuurlijk/73e7708a38433d1df2faf57d98892ff4 to your computer and use it in GitHub Desktop.
Save Tuurlijk/73e7708a38433d1df2faf57d98892ff4 to your computer and use it in GitHub Desktop.
Beating TYPO3 copy-mode-translations into submission
lib.layout.content = COA
lib.layout.content {
10 < styles.content.get
10.select {
where = colPos={field:colPos}
where.insertData = 1
where.stdWrap.noTrimWrap = || AND NOT sys_language_uid = 0|
where.stdWrap.noTrimWrap.if.isTrue.postUserFunc = TypoScript\PageIsCopyModeTranslation->evaluate
includeRecordsWithoutDefaultTranslation = 1
}
10.slide.field = slide
}
<?php
namespace TypoScript;
/**
* Copyright notice
*
* ⓒ 2017 ℳichiel ℛoos <michiel@michielroos.com>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is free
* software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
*/
use TYPO3\CMS\Core\SingletonInterface;
/**
* Class PageIsCopyModeTranslation
*
* A page can be translated by translating each content element to another
* language (translation mode) or by creating separate (not linked) content
* elements on the translated page. In 'translation' mode there is a tight
* coupling between content elements in each language. In Copy mode, the
* user has more freedom.
*
* TYPO3 core does nog handle Copy mode well, therefore we need to detect
* if a page is in copy mode and if so, exclude content elements in the
* default language to avoid them showing up on a translated page in copy
* mode.
*
* A page is in copy mode if nome of the visible elements (including timed
* content elements) has a translation parent: l18n_parent.
*
* The result of this query is cached per page id and language
*
* @package TypoScript
*/
class PageIsCopyModeTranslation implements SingletonInterface
{
/**
* Static cache to avoid may database calls
* when fetching elements for each colPos
*
* @var array
*/
protected static $isCopyMode = [];
/**
* @var \TYPO3\CMS\Core\Database\DatabaseConnection
*/
protected $databaseConnection;
/**
* Initialize
*/
public function __construct()
{
$this->databaseConnection = $GLOBALS['TYPO3_DB'];
}
/**
* Evaluate condition
*
* @return bool
*/
public function evaluate()
{
$languageId = (int)$GLOBALS['TSFE']->sys_language_uid;
if ($languageId === 0) {
return false;
}
$pageId = (int)$GLOBALS['TSFE']->id;
if (array_key_exists($languageId, self::$isCopyMode)
&& array_key_exists($pageId, self::$isCopyMode[$languageId])
) {
return self::$isCopyMode[$languageId][$pageId];
}
$result = (array)$this->databaseConnection->exec_SELECTgetRows(
'uid',
'tt_content',
'hidden = 0
AND deleted = 0
AND NOT l18n_parent = 0' .
' AND sys_language_uid = ' . (int)$GLOBALS['TSFE']->sys_language_uid .
' AND pid = ' . $pageId
);
$pageIsInCopyMode = count($result) === 0;
self::$isCopyMode[$languageId][$pageId] = $pageIsInCopyMode;
return $pageIsInCopyMode;
}
}
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default"/>
<f:section name="header">
</f:section>
<f:section name="content">
<main>
<div class="container">
<!--TYPO3SEARCH_begin-->
<f:cObject typoscriptObjectPath="lib.layout.content" data="{colPos: 0}"/>
</div>
<f:cObject typoscriptObjectPath="lib.layout.content" data="{colPos: 5}"/>
</main>
</f:section>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment