view->assign('controllerName', 'ViewTree'); $this->prepareExtensionAndLangFileOptions(); $this->configurationService->initFileObject( $this->session->getDataByKey('languageFileSelection'), $this->session->getDataByKey('extensionSelection') ); $languageOptions = $this->configurationService->menuLangList( $this->configurationService->getFileObj()->getLocalLangData(), '', $this->backendUser ); $this->assignViewWidthMenuVariables('language', $languageOptions); $referenceLanguageOptions = $this->configurationService->menuLangList( $this->configurationService->getFileObj()->getLocalLangData(), LocalizationUtility::translate('select.nothing', 'lfeditor'), $this->backendUser ); $this->assignViewWidthMenuVariables('referenceLanguage', $referenceLanguageOptions); $this->prepareViewTreeViewMainSectionContent(); } catch (LFException $e) { $this->addLFEFlashMessage($e); } $this->commonViewRenderingActionSettings(); if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) { $this->view->assign('V11', FALSE); return NULL; } else { $this->view->assign('V11', TRUE); return $this->createBackendResponse(); } } /** * This action saves in session currently selected options from selection menus in viewTree view. * It is called on change of selection of any select menu in viewTree view. * * @param string $extensionSelection * @param string $languageFileSelection * @param string $languageSelection * @param string $referenceLanguageSelection * @param string $extKey * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException */ public function changeSelectionAction( $extensionSelection = NULL, $languageFileSelection = NULL, $languageSelection = NULL, $referenceLanguageSelection = NULL, $extKey = '' ): ?\Psr\Http\Message\ResponseInterface { $this->saveSelectionsInSession( $extensionSelection, $languageFileSelection, $referenceLanguageSelection, NULL, NULL, $languageSelection, NULL, NULL, $extKey ); if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) { $this->redirect('viewTree'); return NULL; } else { return $this->redirect('viewTree'); } } /** * Selects explodeToken. * * @param string $explodeToken * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException */ public function selectExplodeTokenAction($explodeToken): ?\Psr\Http\Message\ResponseInterface { $this->session->setDataByKey('explodeToken', $explodeToken); if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) { $this->redirect('viewTree'); return NULL; } else { return $this->redirect('viewTree'); } } /** * Clears extensionAndLangFileOptions cache, and in that way refreshes list of language file options in select box. * */ public function refreshLanguageFileListAction(): ?\Psr\Http\Message\ResponseInterface { $this->clearSelectOptionsCache('extensionAndLangFileOptions'); if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) { $this->redirect('viewTree'); return NULL; } else { return $this->redirect('viewTree'); } } /** * Prepares main section content of viewTree view. * */ protected function prepareViewTreeViewMainSectionContent(): void { $explodeToken = $this->session->getDataByKey('explodeToken'); if ($explodeToken === "") { $explodeToken = '.'; } $langData = $this->configurationService->getFileObj()->getLocalLangData(); $refLangSelection = $this->session->getDataByKey('referenceLanguageSelection'); $languageSelection = $this->session->getDataByKey('languageSelection'); $tree = Functions::genTreeInfoArray($langData[$languageSelection] ?? [], $langData[$refLangSelection] ?? [], $explodeToken); $extConfig = $this->configurationService->getExtConfig(); $treeHide = $extConfig['treeHide']; $fluidTree = []; $levelIndex = 0; $this->addLevelElementsToFluidTree($tree, $levelIndex, NULL, $fluidTree, $treeHide); $this->view->assign('fluidTree', $fluidTree); $this->view->assign('treeHide', $treeHide); $this->view->assign('explodeToken', $explodeToken); } /** * @var integer Width of margin which is added if a branch is missing. */ protected $marginLeftSpaceUnit = 18; /** * Makes tree structure which contains constants. The structure is optimised for recursive use on fluid pages. * * @param array $sourceTree * @param int $level * @param string $parentKey * @param array $fluidTree This structure is used for setting tree-data for use in fluid. * @param boolean $treeHide Default state of tree (TRUE - hidden, FALSE - opened) * @throws LFException * @return void */ protected function addLevelElementsToFluidTree( array $sourceTree, int $level, $parentKey, array &$fluidTree, $treeHide ) { if (empty($sourceTree)) { throw new LFException('failure.select.emptyLanguage', 1); } $constKeys = array_keys($sourceTree[$level]); $index = 0; foreach ($sourceTree[$level] as $constKey => $treeNode) { if ($level === 0 || $treeNode['parent'] === $parentKey) { $fluidTreeElem = []; $fluidTreeElem['label'] = $treeNode['name']; $fluidTreeElem['parent'] = $fluidTree; //$treeNode['parent'];//; // $fluidTreeElem['type'] = $treeNode['type'] ?? ''; $fluidTreeElem['isBottom'] = (!array_key_exists($index + 1, $constKeys) || $sourceTree[$level][$constKeys[$index + 1]]['parent'] !== $treeNode['parent']) ? 1 : 0; $icons = $this->prepareTreeIcons($level, $treeHide, $fluidTreeElem, isset($treeNode['childs'])); $fluidTreeElem['icons'] = $icons; if (array_key_exists($level + 1, $sourceTree)) { $this->addLevelElementsToFluidTree( $sourceTree, $level + 1, $constKey, $fluidTreeElem, $treeHide ); } if ($level > 0) { $fluidTree['children'][$constKey] = $fluidTreeElem; } else { $fluidTree[$constKey] = $fluidTreeElem; } } $index++; } } /** * Sorts and adds icons in tree structure. * * @param int $level Tree level of constant. * @param boolean $treeHide Indicator which shows should all tree elements be closed (hidden) by default. * @param array $fluidTreeElem Element of tree which is built for use on fluid page. * @param boolean $hasChildren Indicator does this tree element have children * @return array */ protected function prepareTreeIcons(int $level, $treeHide, array $fluidTreeElem, $hasChildren): array { $icons = []; $leftMargins = []; $marginLeftSpaceCounter = 0; for ($iconLevel = $level, $currentFluidTreeElem = $fluidTreeElem; $currentFluidTreeElem; $iconLevel--, $currentFluidTreeElem = $currentFluidTreeElem['parent']) { $iconName = '.png'; if ($iconLevel === $level) { if ($currentFluidTreeElem['isBottom']) { $iconName = 'Bottom' . $iconName; } if ($hasChildren) { $iconName = 'tree' . ($treeHide && $level != 0 ? 'Plus' : 'Minus') . $iconName; } else { $iconName = 'join' . $iconName; } } else { if (!$currentFluidTreeElem['isBottom']) { $iconName = 'line' . $iconName; $leftMargins[] = $marginLeftSpaceCounter; $marginLeftSpaceCounter = 0; } else { $marginLeftSpaceCounter += $this->marginLeftSpaceUnit; continue; } } $icons[] = ['name' => $iconName]; } $leftMargins[] = $marginLeftSpaceCounter; for ($iterator = 0, $iconsSize = count($icons); $iterator < $iconsSize; $iterator++) { $icons[$iterator]['marginLeft'] = $leftMargins[$iterator]; } return $icons; } }