Skip to content

Commit

Permalink
Merge pull request #1 from ironsharkde/feature/content-fallback-support
Browse files Browse the repository at this point in the history
add "content_fallback" support
  • Loading branch information
rickfeuerabend authored Nov 9, 2017
2 parents 764042e + 789cfbd commit c791cf8
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 13 deletions.
78 changes: 66 additions & 12 deletions Classes/Helper/InlineHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function getInlineElements($data, $name, $cType, $parentid = "parentid",

// fetching the inline elements
if ($childTable == "tt_content") {
$sql = $GLOBALS["TYPO3_DB"]->exec_SELECTquery(
$queryResult = $GLOBALS["TYPO3_DB"]->exec_SELECTquery(
"*", $childTable, $parentid . " = '" . $parentUid .
"' AND sys_language_uid IN (-1," . $sysLangUid . ")"
. ' AND ('
Expand All @@ -186,21 +186,47 @@ public function getInlineElements($data, $name, $cType, $parentid = "parentid",
. $enableFields, "", "sorting"
);
} else {
$sql = $GLOBALS["TYPO3_DB"]->exec_SELECTquery(
"*", $childTable, $parentid . " = '" . $parentUid .
"' AND parenttable = '" . $parenttable .
"' AND sys_language_uid IN (-1," . $sysLangUid . ")"
. ' AND ('
. $childTable . '.t3ver_wsid=0 OR '
. $childTable . '.t3ver_wsid=' . (int)$GLOBALS['BE_USER']->workspace
. ' AND ' . $childTable . '.pid<>-1'
. ')'
. $enableFields, "", "sorting"
$queryResult = $this->getQueryResult(
$parentid,
$parenttable,
$childTable,
$parentUid,
$sysLangUid,
$enableFields
);
}

// and recursively add them to an array
$elements = array();
$elements = $this->fetchElements($name, $cType, $childTable, $queryResult);

if (empty($elements) && $GLOBALS['TSFE']->sys_language_mode == 'content_fallback') {

$queryResult = $this->getQueryResult(
$parentid,
$parenttable,
$childTable,
$parentUid,
$GLOBALS['TSFE']->sys_language_content,
$enableFields
);

$elements = $this->fetchElements($name, $cType, $childTable, $queryResult);
}

return $elements;
}

/**
* and recursively add them to an array
* @param $name
* @param $cType
* @param $childTable
* @param $sql
* @return array
*/
protected function fetchElements($name, $cType, $childTable, $sql)
{
$elements = [];
while ($element = $GLOBALS["TYPO3_DB"]->sql_fetch_assoc($sql)) {
if (TYPO3_MODE == 'FE') {
$GLOBALS['TSFE']->sys_page->versionOL($childTable, $element);
Expand All @@ -216,4 +242,32 @@ public function getInlineElements($data, $name, $cType, $parentid = "parentid",

return $elements;
}

/**
* @param $parentid
* @param $parenttable
* @param $childTable
* @param $parentUid
* @param $sysLangUid
* @param $enableFields
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
*/
protected function getQueryResult($parentid, $parenttable, $childTable, $parentUid, $sysLangUid, $enableFields)
{
return $GLOBALS["TYPO3_DB"]->exec_SELECTquery(
"*",
$childTable,
$parentid . " = '" . $parentUid .
"' AND parenttable = '" . $parenttable .
"' AND sys_language_uid IN (-1," . $sysLangUid . ")"
. ' AND ('
. $childTable . '.t3ver_wsid=0 OR '
. $childTable . '.t3ver_wsid=' . (int)$GLOBALS['BE_USER']->workspace
. ' AND ' . $childTable . '.pid<>-1'
. ')'
. $enableFields,
"",
"sorting"
);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"license": "GPL-2.0+",
"version": "3.0.2",
"version": "3.0.3",
"require": {
"php": "^7.0",
"typo3/cms-core": "^8.7"
Expand Down

0 comments on commit c791cf8

Please sign in to comment.