/** * Returns the actions for the given node information's * * @param stdClass $nodeData * @return array */ public function getActionsForNodeArray($nodeData) { /** @var $node \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */ $node = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode', (array) $nodeData); $node->setRecord(\TYPO3\CMS\Backend\Tree\Pagetree\Commands::getNodeRecord($node->getId())); $this->initDataProvider(); $this->dataProvider->setContextMenuType('table.' . $node->getType()); $actionCollection = $this->dataProvider->getActionsForNode($node); if ($actionCollection instanceof \TYPO3\CMS\Backend\ContextMenu\ContextMenuActionCollection) { $actions = $actionCollection->toArray(); } return $actions; }
/** * Returns the actions for the given node information's * * @param \stdClass $nodeData * @return array */ public function getActionsForNodeArray($nodeData) { $node = GeneralUtility::makeInstance(PagetreeNode::class, (array) $nodeData); $node->setRecord(Commands::getNodeRecord($node->getId())); $this->initDataProvider(); $this->dataProvider->setContextMenuType('table.' . $node->getType()); $actionCollection = $this->dataProvider->getActionsForNode($node); $actions = []; if ($actionCollection instanceof ContextMenuActionCollection) { $actions = $actionCollection->toArray(); } return $actions; }
/** * Delete the page * * @param stdClass $nodeData * @return array */ public function deleteNode($nodeData) { /** @var $node \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */ $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array) $nodeData); try { Commands::deleteNode($node); $returnValue = array(); if ($GLOBALS['BE_USER']->workspace) { $record = Commands::getNodeRecord($node->getId()); if ($record['_ORIG_uid']) { $newNode = Commands::getNewNode($record); $returnValue = $newNode->toArray(); } } } catch (\Exception $exception) { $returnValue = array('success' => false, 'message' => $exception->getMessage()); } return $returnValue; }
/** * Delete the page * * @param \stdClass $nodeData * @return array */ public function deleteNode($nodeData) { /** @var $node PagetreeNode */ $node = GeneralUtility::makeInstance(PagetreeNode::class, (array) $nodeData); try { Commands::deleteNode($node); $returnValue = []; if (static::getBackendUser()->workspace) { $record = Commands::getNodeRecord($node->getId()); if ($record['_ORIG_uid']) { $newNode = Commands::getNewNode($record); $returnValue = $newNode->toArray(); } } } catch (\Exception $exception) { $returnValue = ['success' => false, 'message' => $exception->getMessage()]; } return $returnValue; }
/** * Returns a node collection of filtered nodes * * @param \TYPO3\CMS\Backend\Tree\TreeNode $node * @param string $searchFilter * @param int $mountPoint * @return \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection the filtered nodes */ public function getFilteredNodes(\TYPO3\CMS\Backend\Tree\TreeNode $node, $searchFilter, $mountPoint = 0) { /** @var $nodeCollection \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection */ $nodeCollection = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection::class); $records = $this->getSubpages(-1, $searchFilter); if (!is_array($records) || empty($records)) { return $nodeCollection; } elseif (count($records) > 500) { return $nodeCollection; } // check no temporary mountpoint is used $mountPoints = (int) $GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint']; if (!$mountPoints) { $mountPoints = array_map('intval', $GLOBALS['BE_USER']->returnWebmounts()); $mountPoints = array_unique($mountPoints); } else { $mountPoints = [$mountPoints]; } $isNumericSearchFilter = is_numeric($searchFilter) && $searchFilter > 0; $searchFilterQuoted = preg_quote($searchFilter, '/'); $nodeId = (int) $node->getId(); $processedRecordIds = []; foreach ($records as $record) { if ((int) $record['t3ver_wsid'] !== (int) $GLOBALS['BE_USER']->workspace && (int) $record['t3ver_wsid'] !== 0) { continue; } $liveVersion = BackendUtility::getLiveVersionOfRecord('pages', $record['uid'], 'uid'); if ($liveVersion !== null) { $record = $liveVersion; } $record = Commands::getNodeRecord($record['uid'], false); if ((int) $record['pid'] === -1 || in_array($record['uid'], $this->hiddenRecords) || in_array($record['uid'], $processedRecordIds)) { continue; } $processedRecordIds[] = $record['uid']; $rootline = BackendUtility::BEgetRootLine($record['uid'], '', $GLOBALS['BE_USER']->workspace != 0); $rootline = array_reverse($rootline); if (!in_array(0, $mountPoints, true)) { $isInsideMountPoints = false; foreach ($rootline as $rootlineElement) { if (in_array((int) $rootlineElement['uid'], $mountPoints, true)) { $isInsideMountPoints = true; break; } } if (!$isInsideMountPoints) { continue; } } $reference = $nodeCollection; $inFilteredRootline = false; $amountOfRootlineElements = count($rootline); for ($i = 0; $i < $amountOfRootlineElements; ++$i) { $rootlineElement = $rootline[$i]; $rootlineElement['uid'] = (int) $rootlineElement['uid']; $isInWebMount = (int) $GLOBALS['BE_USER']->isInWebMount($rootlineElement['uid']); if (!$isInWebMount || $rootlineElement['uid'] === (int) $mountPoints[0] && $rootlineElement['uid'] !== $isInWebMount) { continue; } if ((int) $rootlineElement['pid'] === $nodeId || $rootlineElement['uid'] === $nodeId || $rootlineElement['uid'] === $isInWebMount && in_array($rootlineElement['uid'], $mountPoints, true)) { $inFilteredRootline = true; } if (!$inFilteredRootline || $rootlineElement['uid'] === $mountPoint) { continue; } $rootlineElement = Commands::getNodeRecord($rootlineElement['uid'], false); $ident = (int) $rootlineElement['sorting'] . (int) $rootlineElement['uid']; if ($reference && $reference->offsetExists($ident)) { /** @var $refNode \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */ $refNode = $reference->offsetGet($ident); $refNode->setExpanded(true); $refNode->setLeaf(false); $reference = $refNode->getChildNodes(); if ($reference == null) { $reference = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection::class); $refNode->setChildNodes($reference); } } else { $refNode = Commands::getNewNode($rootlineElement, $mountPoint); $replacement = '<span class="typo3-pagetree-filteringTree-highlight">$1</span>'; if ($isNumericSearchFilter && (int) $rootlineElement['uid'] === (int) $searchFilter) { $text = str_replace('$1', $refNode->getText(), $replacement); } else { $text = preg_replace('/(' . $searchFilterQuoted . ')/iu', $replacement, $refNode->getText()); } $refNode->setText($text, $refNode->getTextSourceField(), $refNode->getPrefix(), $refNode->getSuffix()); /** @var $childCollection \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection */ $childCollection = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection::class); if ($i + 1 >= $amountOfRootlineElements) { $childNodes = $this->getNodes($refNode, $mountPoint); foreach ($childNodes as $childNode) { /** @var $childNode \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */ $childRecord = $childNode->getRecord(); $childIdent = (int) $childRecord['sorting'] . (int) $childRecord['uid']; $childCollection->offsetSet($childIdent, $childNode); } $refNode->setChildNodes($childNodes); } $refNode->setChildNodes($childCollection); $reference->offsetSet($ident, $refNode); $reference->ksort(); $reference = $childCollection; } } } foreach ($this->processCollectionHookObjects as $hookObject) { /** @var $hookObject \TYPO3\CMS\Backend\Tree\Pagetree\CollectionProcessorInterface */ $hookObject->postProcessFilteredNodes($node, $searchFilter, $mountPoint, $nodeCollection); } return $nodeCollection; }
/** * Returns a node collection of filtered nodes * * @param \TYPO3\CMS\Backend\Tree\TreeNode $node * @param string $searchFilter * @param integer $mountPoint * @return \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection the filtered nodes */ public function getFilteredNodes(\TYPO3\CMS\Backend\Tree\TreeNode $node, $searchFilter, $mountPoint = 0) { /** @var $nodeCollection \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection */ $nodeCollection = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNodeCollection'); $records = $this->getSubpages(-1, $searchFilter); if (!is_array($records) || !count($records)) { return $nodeCollection; } elseif (count($records) > 500) { return $nodeCollection; } // check no temporary mountpoint is used $mountPoints = intval($GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint']); if (!$mountPoints) { $mountPoints = array_map('intval', $GLOBALS['BE_USER']->returnWebmounts()); $mountPoints = array_unique($mountPoints); } else { $mountPoints = array($mountPoints); } $isNumericSearchFilter = is_numeric($searchFilter) && $searchFilter > 0; $nodeId = intval($node->getId()); foreach ($records as $record) { $record = \TYPO3\CMS\Backend\Tree\Pagetree\Commands::getNodeRecord($record['uid']); if (intval($record['pid']) === -1 || in_array($record['uid'], $this->hiddenRecords)) { continue; } $rootline = \TYPO3\CMS\Backend\Utility\BackendUtility::BEgetRootLine($record['uid'], '', $GLOBALS['BE_USER']->workspace != 0); $rootline = array_reverse($rootline); if ($nodeId === 0) { array_shift($rootline); } if ($mountPoints != array(0)) { $isInsideMountPoints = FALSE; foreach ($rootline as $rootlineElement) { if (in_array(intval($rootlineElement['uid']), $mountPoints, TRUE)) { $isInsideMountPoints = TRUE; break; } } if (!$isInsideMountPoints) { continue; } } $reference = $nodeCollection; $inFilteredRootline = FALSE; $amountOfRootlineElements = count($rootline); for ($i = 0; $i < $amountOfRootlineElements; ++$i) { $rootlineElement = $rootline[$i]; if (intval($rootlineElement['pid']) === $nodeId || intval($rootlineElement['uid']) === $nodeId) { $inFilteredRootline = TRUE; } if (!$inFilteredRootline) { continue; } $rootlineElement = \TYPO3\CMS\Backend\Tree\Pagetree\Commands::getNodeRecord($rootlineElement['uid']); $ident = intval($rootlineElement['sorting']) . intval($rootlineElement['uid']); if ($reference && $reference->offsetExists($ident)) { /** @var $refNode \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */ $refNode = $reference->offsetGet($ident); $refNode->setExpanded(TRUE); $refNode->setLeaf(FALSE); $reference = $refNode->getChildNodes(); if ($reference == NULL) { $reference = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNodeCollection'); $refNode->setChildNodes($reference); } } else { $refNode = \TYPO3\CMS\Backend\Tree\Pagetree\Commands::getNewNode($rootlineElement, $mountPoint); $replacement = '<span class="typo3-pagetree-filteringTree-highlight">$1</span>'; if ($isNumericSearchFilter && intval($rootlineElement['uid']) === intval($searchFilter)) { $text = str_replace('$1', $refNode->getText(), $replacement); } else { $text = preg_replace('/(' . $searchFilter . ')/i', $replacement, $refNode->getText()); } $refNode->setText($text, $refNode->getTextSourceField(), $refNode->getPrefix(), $refNode->getSuffix()); /** @var $childCollection \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection */ $childCollection = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNodeCollection'); if ($i + 1 >= $amountOfRootlineElements) { $childNodes = $this->getNodes($refNode, $mountPoint); foreach ($childNodes as $childNode) { /** @var $childNode \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */ $childRecord = $childNode->getRecord(); $childIdent = intval($childRecord['sorting']) . intval($childRecord['uid']); $childCollection->offsetSet($childIdent, $childNode); } $refNode->setChildNodes($childNodes); } $refNode->setChildNodes($childCollection); $reference->offsetSet($ident, $refNode); $reference->ksort(); $reference = $childCollection; } } } foreach ($this->processCollectionHookObjects as $hookObject) { /** @var $hookObject t3lib_tree_pagetree_interfaces_collectionprocessor */ $hookObject->postProcessFilteredNodes($node, $searchFilter, $mountPoint, $nodeCollection); } return $nodeCollection; }