Skip to content

Commit

Permalink
[TASK] make NewsDatabaseTreeDataProvider compatible for TYPO3 v12
Browse files Browse the repository at this point in the history
  • Loading branch information
rupertgermann committed Sep 26, 2024
1 parent 7264a93 commit efbd396
Showing 1 changed file with 29 additions and 43 deletions.
72 changes: 29 additions & 43 deletions Classes/Tree/TableConfiguration/NewsDatabaseTreeDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

/**
* TCA tree data provider
*
* @todo fix for TYPO3 v12
*/
class NewsDatabaseTreeDataProvider extends DatabaseTreeDataProvider
{
Expand All @@ -35,54 +33,42 @@ protected function getChildrenOf(TreeNode $node, $level): ?TreeNodeCollection
$allowedItems = $this->getBeUser()->getTSConfig()['tt_newsPerms.']['tt_news_cat.']['allowedItems'] ?? false;
$allowedItems = $allowedItems ? GeneralUtility::intExplode(',', $allowedItems) : Div::getAllowedTreeIDs();

$storage = null;

if ($node->getId() !== 0 && !in_array($node->getId(), $allowedItems)) {
return null;
}

$nodeData = null;
if ($node->getId() !== 0) {
$nodeData = Database::getInstance()->exec_SELECTgetSingleRow(
'*',
$this->tableName,
'uid=' . $node->getId()
);
if ($node->getId() !== 0 && $node->getId() !== '0') {
if (is_array($this->availableItems[(int)$node->getId()] ?? false)) {
$nodeData = $this->availableItems[(int)$node->getId()];
} else {
$nodeData = BackendUtility::getRecord($this->tableName, $node->getId(), '*', '', false);
}
}

if ($nodeData == null) {
if (empty($nodeData)) {
$nodeData = [
'uid' => 0,
$this->getLookupField() => '',
$this->lookupField => '',
];
}

$storage = null;
$children = $this->getRelatedRecords($nodeData);
if (empty($children)) {
return null;
}

/** @var $storage TreeNodeCollection */
$storage = GeneralUtility::makeInstance(TreeNodeCollection::class);
foreach ($children as $child) {
/** @var TreeNode $node */
$node = GeneralUtility::makeInstance(TreeNode::class);
if (!empty($children)) {
$storage = GeneralUtility::makeInstance(TreeNodeCollection::class);
foreach ($children as $child) {
$node = GeneralUtility::makeInstance(TreeNode::class, $this->availableItems[(int)$child] ?? []);

if (!in_array($child, $allowedItems)) {
$this->setItemUnselectableList(array_merge($this->getItemUnselectableList() ?? [], [$child]));
}

$node->setId($child);
if (!in_array($child, $allowedItems)) {
$this->setItemUnselectableList(array_merge($this->getItemUnselectableList() ?? [], [$child]));
}

if ($level < $this->levelMaximum) {
$children = $this->getChildrenOf($node, $level + 1);

if ($children !== null) {
$node->setChildNodes($children);
$node->setId($child);
if ($level < $this->levelMaximum) {
$children = $this->getChildrenOf($node, $level + 1);
if ($children !== null) {
$node->setChildNodes($children);
}
}
$storage->append($node);
}

$storage->append($node);
}

return $storage;
Expand All @@ -98,24 +84,25 @@ protected function getChildrenOf(TreeNode $node, $level): ?TreeNodeCollection
*/
protected function buildRepresentationForNode(TreeNode $basicNode, DatabaseTreeNode $parent = null, $level = 0): DatabaseTreeNode
{
/** @var DatabaseTreeNode $node */
$node = GeneralUtility::makeInstance(DatabaseTreeNode::class);
$row = [];
if ($basicNode->getId() == 0) {
$node->setSelected(false);
$node->setExpanded(true);
$node->setLabel($this->getLanguageService()->sL($GLOBALS['TCA'][$this->tableName]['ctrl']['title']));
$node->setLabel($this->getLanguageService()?->sL($GLOBALS['TCA'][$this->tableName]['ctrl']['title']));
} else {
$row = BackendUtility::getRecordWSOL($this->tableName, (int)$basicNode->getId(), '*', '', false);
if ($basicNode->getAdditionalData() === []) {
$row = BackendUtility::getRecordWSOL($this->tableName, (int)$basicNode->getId(), '*', '', false) ?? [];
} else {
$row = $basicNode->getAdditionalData();
}
$node->setLabel(BackendUtility::getRecordTitle($this->tableName, $row) ?: $basicNode->getId());
$node->setSelected(GeneralUtility::inList($this->getSelectedList(), $basicNode->getId()));
$node->setExpanded($this->isExpanded($basicNode));
}
$node->setId($basicNode->getId());
$node->setSelectable(!GeneralUtility::inList($this->getNonSelectableLevelList(), (string)$level) && !in_array($basicNode->getId(), $this->getItemUnselectableList()));
$node->setSortValue($this->nodeSortValues[$basicNode->getId()] ?? '');

/** @var IconFactory $iconFactory */
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);

if (in_array($basicNode->getId(), $this->getItemUnselectableList())) {
Expand All @@ -131,7 +118,6 @@ protected function buildRepresentationForNode(TreeNode $basicNode, DatabaseTreeN
$node->setParentNode($parent);
if ($basicNode->hasChildNodes()) {
$node->setHasChildren(true);
/** @var SortedTreeNodeCollection $childNodes */
$childNodes = GeneralUtility::makeInstance(SortedTreeNodeCollection::class);
$tempNodes = [];
foreach ($basicNode->getChildNodes() as $child) {
Expand Down

0 comments on commit efbd396

Please sign in to comment.