Skip to content

Instantly share code, notes, and snippets.

@peterkraume
Created July 20, 2017 09:51
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterkraume/1c0feb30440449ba1c708aa5ea8d7991 to your computer and use it in GitHub Desktop.
Save peterkraume/1c0feb30440449ba1c708aa5ea8d7991 to your computer and use it in GitHub Desktop.
Backport for TYPO3 8.7: PageLayoutView - Allow to disable copy- / translate- buttons

This patch backports the new feature to disable copy- / translate- buttons from TYPO3 9.x to TYPO3 8.7

See https://review.typo3.org/#/c/52345/ for details.

The localization actions "Translate" and "Copy" are then toggleable by PageTS and UserTS.

mod.web_layout.localization.enableCopy = 1
mod.web_layout.localization.enableTranslate = 1
{
"repositories": [
{ "type": "composer", "url": "https://composer.typo3.org/" }
],
"name": "typo3/cms-base-distribution",
"description" : "TYPO3 CMS Base Distribution",
"license": "GPL-2.0+",
"require": {
"typo3/cms": "^8.7"
},
"extra": {
"typo3/cms": {
"cms-package-dir": "{$vendor-dir}/typo3/cms",
"web-dir": "web"
}
},
"autoload": {
"psr-4": {
"Bgm\\BgmThemeCustomer\\": "web/typo3conf/ext/bgm_theme_customer/Classes"
}
}
}
<?php
defined('TYPO3_MODE') or die();
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\\CMS\\Backend\\View\\PageLayoutView'] = array(
'className' => 'Bgm\\BgmThemeCustomer\\Xclass\\PageLayoutView'
);
mod {
web_layout {
// disable translation mode for content elements
// backported feature from TYPO3 9.x. See Xclass PageLayoutView.php for details
localization.enableTranslate = 0
}
}
<?php
namespace Bgm\BgmThemeCustomer\Xclass;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Child class for the Web > Page module
*/
class PageLayoutView extends \TYPO3\CMS\Backend\View\PageLayoutView
{
/**
* Creates button which is used to create copies of records..
*
* @param array $defaultLanguageUids Numeric array with uids of tt_content elements in the default language
* @param int $lP Sys language UID
* @param int $colPos Column position
* @return string "Copy languages" button, if available.
*/
public function newLanguageButton($defaultLanguageUids, $lP, $colPos = 0)
{
$lP = (int)$lP;
if (!$this->doEdit || !$lP) {
return '';
}
$theNewButton = '';
// backport of https://review.typo3.org/#/c/52345/ from TYPO3 9.x for TYPO3 8.7
$localizationTsConfig = BackendUtility::getModTSconfig($this->id, 'mod.web_layout.localization');
$allowCopy = isset($localizationTsConfig['properties']['enableCopy'])
? (int)$localizationTsConfig['properties']['enableCopy'] === 1
: true;
$allowTranslate = isset($localizationTsConfig['properties']['enableTranslate'])
? (int)$localizationTsConfig['properties']['enableTranslate'] === 1
: true;
// end backport
if (!empty($this->languageHasTranslationsCache[$lP])) {
if (isset($this->languageHasTranslationsCache[$lP]['hasStandAloneContent'])) {
$allowTranslate = false;
}
if (isset($this->languageHasTranslationsCache[$lP]['hasTranslations'])) {
$allowCopy = false;
}
}
if (isset($this->contentElementCache[$lP][$colPos]) && is_array($this->contentElementCache[$lP][$colPos])) {
foreach ($this->contentElementCache[$lP][$colPos] as $record) {
$key = array_search($record['l10n_source'], $defaultLanguageUids);
if ($key !== false) {
unset($defaultLanguageUids[$key]);
}
}
}
if (!empty($defaultLanguageUids)) {
$theNewButton =
'<input'
. ' class="btn btn-default t3js-localize"'
. ' type="button"'
. ' disabled'
. ' value="' . htmlspecialchars($this->getLanguageService()->getLL('newPageContent_translate')) . '"'
. ' data-has-elements="' . (int)!empty($this->contentElementCache[$lP][$colPos]) . '"'
. ' data-allow-copy="' . (int)$allowCopy . '"'
. ' data-allow-translate="' . (int)$allowTranslate . '"'
. ' data-table="tt_content"'
. ' data-page-id="' . (int)GeneralUtility::_GP('id') . '"'
. ' data-language-id="' . $lP . '"'
. ' data-language-name="' . htmlspecialchars($this->tt_contentConfig['languageCols'][$lP]) . '"'
. ' data-colpos-id="' . $colPos . '"'
. ' data-colpos-name="' . BackendUtility::getProcessedValue('tt_content', 'colPos', $colPos) . '"'
. '/>';
}
return '<div class="t3-page-lang-copyce">' . $theNewButton . '</div>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment