Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

Commit

Permalink
[FEATURE] Restrict referenced content to column language if configured
Browse files Browse the repository at this point in the history
Change-Id: I62637e9abbb2dc768f1e5eb166238730da833f3e
Resolves: #84246
Release: master, 8-0, 7-0
Reviewed-on: https://review.typo3.org/56218
Reviewed-by: Eric Chavaillaz <eric@hemmer.ch>
Tested-by: Eric Chavaillaz <eric@hemmer.ch>
Reviewed-by: Jo Hasenau <info@cybercraft.de>
Tested-by: Jo Hasenau <info@cybercraft.de>
  • Loading branch information
Bunnyfield committed Mar 16, 2018
1 parent 0997dc9 commit 7636368
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
34 changes: 29 additions & 5 deletions Classes/Hooks/DrawItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
class DrawItem implements PageLayoutViewDrawItemHookInterface, SingletonInterface
{

/**
* @var array
*/
protected $extentensionConfiguration;

/**
* @var Helper
*/
Expand Down Expand Up @@ -96,6 +101,7 @@ class DrawItem implements PageLayoutViewDrawItemHookInterface, SingletonInterfac

public function __construct()
{
$this->extentensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['gridelements']);
$this->setLanguageService($GLOBALS['LANG']);
$this->helper = Helper::getInstance();
$this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
Expand Down Expand Up @@ -1098,10 +1104,10 @@ protected function renderCTypeShortcut(PageLayoutView $parentObject, &$row)
foreach ($shortcutItems as $shortcutItem) {
$shortcutItem = trim($shortcutItem);
if (strpos($shortcutItem, 'pages_') !== false) {
$this->collectContentDataFromPages($shortcutItem, $collectedItems, $row['recursive'], $row['uid']);
$this->collectContentDataFromPages($shortcutItem, $collectedItems, $row['recursive'], $row['uid'], $row['sys_language_uid']);
} else {
if (strpos($shortcutItem, '_') === false || strpos($shortcutItem, 'tt_content_') !== false) {
$this->collectContentData($shortcutItem, $collectedItems, $row['uid']);
$this->collectContentData($shortcutItem, $collectedItems, $row['uid'], $row['sys_language_uid']);
}
}
}
Expand Down Expand Up @@ -1129,14 +1135,16 @@ protected function renderCTypeShortcut(PageLayoutView $parentObject, &$row)
* @param array $collectedItems : The collected item data rows ordered by parent position, column position and sorting
* @param int $recursive : The number of levels for the recursion
* @param int $parentUid : uid of the referencing tt_content record
* @param int $language : sys_language_uid of the referencing tt_content record
*
* @return void
*/
protected function collectContentDataFromPages(
$shortcutItem,
&$collectedItems,
$recursive = 0,
$parentUid
$parentUid,
$language = 0
) {
$itemList = str_replace('pages_', '', $shortcutItem);
if ($recursive) {
Expand All @@ -1148,6 +1156,7 @@ protected function collectContentDataFromPages(
$itemList = GeneralUtility::intExplode(',', $itemList);

$queryBuilder = $this->getQueryBuilder();

$items = $queryBuilder
->select('*')
->addSelectLiteral($queryBuilder->expr()->inSet('pid',
Expand All @@ -1158,7 +1167,8 @@ protected function collectContentDataFromPages(
$queryBuilder->createNamedParameter((int)$parentUid, \PDO::PARAM_INT)),
$queryBuilder->expr()->in('pid',
$queryBuilder->createNamedParameter($itemList, Connection::PARAM_INT_ARRAY)),
$queryBuilder->expr()->gte('colPos', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))
$queryBuilder->expr()->gte('colPos', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
$queryBuilder->expr()->in('sys_language_uid', $queryBuilder->createNamedParameter([0, -1], Connection::PARAM_INT_ARRAY))
)
->orderBy('inSet')
->addOrderBy('colPos')
Expand All @@ -1167,6 +1177,12 @@ protected function collectContentDataFromPages(
->fetchAll();

foreach ($items as $item) {
if (!empty($this->extentensionConfiguration['overlayShortcutTranslation']) && $language > 0) {
$translatedItem = BackendUtility::getRecordLocalization('tt_content', $item['uid'], $language);
if (!empty($translatedItem)) {
$item = array_shift($translatedItem);
}
}
if ($this->helper->getBackendUser()->workspace > 0) {
BackendUtility::workspaceOL('tt_content', $item, $this->helper->getBackendUser()->workspace);
}
Expand All @@ -1181,10 +1197,11 @@ protected function collectContentDataFromPages(
* @param string $shortcutItem : The tt_content element to fetch the data from
* @param array $collectedItems : The collected item data row
* @param int $parentUid : uid of the referencing tt_content record
* @param int $language : sys_language_uid of the referencing tt_content record
*
* @return void
*/
protected function collectContentData($shortcutItem, &$collectedItems, $parentUid)
protected function collectContentData($shortcutItem, &$collectedItems, $parentUid, $language)
{
$shortcutItem = str_replace('tt_content_', '', $shortcutItem);
if ((int)$shortcutItem !== (int)$parentUid) {
Expand All @@ -1203,6 +1220,13 @@ protected function collectContentData($shortcutItem, &$collectedItems, $parentUi
->execute()
->fetch();

if (!empty($this->extentensionConfiguration['overlayShortcutTranslation']) && $language > 0) {
$translatedItem = BackendUtility::getRecordLocalization('tt_content', $item['uid'], $language);
if (!empty($translatedItem)) {
$item = array_shift($translatedItem);
}
}

if ($this->helper->getBackendUser()->workspace > 0) {
BackendUtility::workspaceOL(
'tt_content',
Expand Down
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<trans-unit id="nestingInListModule" xml:space="preserve">
<source>Enable nesting in list module</source>
</trans-unit>
<trans-unit id="overlayShortcutTranslation" xml:space="preserve">
<source>Use language overlay for content and page records referenced in shortcut elements.</source>
</trans-unit>
</body>
</file>
</xliff>
3 changes: 3 additions & 0 deletions ext_conf_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ additionalStylesheet =

# cat=basic; type=boolean; label=LLL:EXT:gridelements/Resources/Private/Language/locallang.xlf:nestingInListModule
nestingInListModule = 0

# cat=basic; type=boolean; label=LLL:EXT:gridelements/Resources/Private/Language/locallang.xlf:overlayShortcutTranslation
overlayShortcutTranslation = 0
6 changes: 5 additions & 1 deletion ext_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@
';

$GLOBALS['TBE_STYLES']['skins']['gridelements']['name'] = 'gridelements';
$GLOBALS['TBE_STYLES']['skins']['gridelements']['stylesheetDirectories']['structure'] = 'EXT:' . ($_EXTKEY) . '/Resources/Public/Backend/Css/Skin/';
$GLOBALS['TBE_STYLES']['skins']['gridelements']['stylesheetDirectories']['gridelements_structure'] = 'EXT:' . ($_EXTKEY) . '/Resources/Public/Backend/Css/Skin/';
if ($_EXTCONF['additionalStylesheet'] && \TYPO3\CMS\Core\Utility\GeneralUtility::validPathStr($_EXTCONF['additionalStylesheet'])) {
$GLOBALS['TBE_STYLES']['skins']['gridelements']['stylesheetDirectories']['gridelements_additional'] = $_EXTCONF['additionalStylesheet'];
}

}

// Hooks
Expand Down

0 comments on commit 7636368

Please sign in to comment.