diff --git a/Classes/Controller/BackendController.php b/Classes/Controller/BackendController.php index 30452a16b094762405a79df38f52cca6611be563..6720edb4fb69d3b925832901580c8f424d3affc1 100644 --- a/Classes/Controller/BackendController.php +++ b/Classes/Controller/BackendController.php @@ -30,6 +30,7 @@ use SGalinski\SgJobs\Service\BackendService; use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\VersionNumberUtility; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; /** @@ -43,6 +44,13 @@ class BackendController extends ActionController { */ protected $docHeaderComponent; + /** + * The uid of the current root page + * + * @var int + */ + private $rootPageUid = 0; + /** * Show all job offers and options to manage them * @@ -53,11 +61,26 @@ class BackendController extends ActionController { // create doc header component try { $pageUid = (int) GeneralUtility::_GP('id'); + + if ($pageUid) { + $this->rootPageUid = BackendService::getRootUidByPageUid($pageUid); + } + + // create docheader + buttons $pageInfo = BackendUtility::readPageAccess($pageUid, $GLOBALS['BE_USER']->getPagePermsClause(1)); $this->docHeaderComponent = GeneralUtility::makeInstance(DocHeaderComponent::class); $this->docHeaderComponent->setMetaInformation($pageInfo); BackendService::makeButtons($this->docHeaderComponent, $this->request); + // if we are not on a root page, display the root pages to the user + if (!$this->rootPageUid) { + $this->view->assign('rootOptions', BackendService::getRootOptions()); + } + + $this->view->assign('pageUid', $pageUid); + $this->view->assign('rootPageUid', $this->rootPageUid); + $this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent()); + $this->view->assign('typo3Version', VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version)); $this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent()); } catch (\Exception $exception) { // check for NULL value in view and render an error message diff --git a/Classes/Service/BackendService.php b/Classes/Service/BackendService.php index 19e49c8f2a4ea7a027932790e3e5ba126c6385fd..68fdc0a7967139264a9a6c0bc7b33f5f0866d8c3 100644 --- a/Classes/Service/BackendService.php +++ b/Classes/Service/BackendService.php @@ -47,7 +47,7 @@ class BackendService { * @return array * @throws \InvalidArgumentException */ - public static function getPages() { + public static function getPages(): array { $out = []; /** @var $databaseConnection DatabaseConnection */ $databaseConnection = $GLOBALS['TYPO3_DB']; @@ -60,10 +60,10 @@ class BackendService { foreach ($rows as $row) { $pageInfo = BackendUtility::readPageAccess($row['uid'], $GLOBALS['BE_USER']->getPagePermsClause(1)); if ($pageInfo) { - $rootline = BackendUtility::BEgetRootLine($pageInfo['uid'], '', true); + $rootline = BackendUtility::BEgetRootLine($pageInfo['uid'], '', TRUE); ksort($rootline); $path = '/root'; - foreach($rootline as $page) { + foreach ($rootline as $page) { $path .= '/p' . dechex($page['uid']); } $pageInfo['path'] = $path; @@ -116,7 +116,7 @@ class BackendService { * @param int $currentPid * @return int */ - public static function getSiteRoot($currentPid) { + public static function getSiteRoot($currentPid): int { $rootLine = BackendUtility::BEgetRootLine((int) $currentPid); $siteRoot = ['uid' => 0]; @@ -129,4 +129,49 @@ class BackendService { return $siteRoot['uid']; } + + /** + * Returns the root uid based on the given page uid + * + * @param int $pageUid + * @return int + */ + public static function getRootUidByPageUid($pageUid): int { + $out = 0; + $pageRootline = BackendUtility::BEgetRootLine($pageUid); + foreach ($pageRootline as $pageData) { + if ($pageData['is_siteroot']) { + $out = (int) $pageData['uid']; + break; + } + } + return $out; + } + + /** + * Get the root pages + * + * @return array + */ + public static function getRootOptions(): array { + $rootOptionRows = (array) BackendUtility::getRecordsByField('pages', 'is_siteroot', 1, '', '', 'sorting'); + $rootOptions = []; + foreach ($rootOptionRows as $row) { + $pageInfo = BackendUtility::readPageAccess($row['uid'], $GLOBALS['BE_USER']->getPagePermsClause(1)); + if ($pageInfo) { + $rootline = BackendUtility::BEgetRootLine($pageInfo['uid'], '', TRUE); + ksort($rootline); + $path = '/root'; + foreach ($rootline as $page) { + $path .= '/p' . dechex($page['uid']); + } + $pageInfo['path'] = $path; + $pageInfo['_thePathFull'] = substr($pageInfo['_thePathFull'], 1); + $pageInfo['_thePathFull'] = substr($pageInfo['_thePathFull'], 0, -1); + $rootOptions[] = $pageInfo; + } + } + + return $rootOptions; + } } diff --git a/Resources/Private/Partials/SelectRoot.html b/Resources/Private/Partials/SelectRoot.html new file mode 100644 index 0000000000000000000000000000000000000000..6ee2968b847ac0c85c30ee4a4d3fc10d1e9db253 --- /dev/null +++ b/Resources/Private/Partials/SelectRoot.html @@ -0,0 +1,25 @@ +{namespace sg=SGalinski\SgJobs\ViewHelpers} +<p> + <f:translate key="backend.selectRootPage" /> +</p> +<f:if condition="{pages}"> + <div class="panel panel-default recordlist"> + <div class="table-fit"> + <table data-table="pages" class="table table-striped table-hover"> + <tbody> + <f:for each="{pages}" as="page"> + <tr data-uid="{page.uid}"> + <td nowrap="nowrap" class="col-title"> + <a href="#" onclick="sgRouteGoToPage({page.uid}, '{page.path}'); return false;"> + <f:format.raw> + <sg:backend.icon table="pages" row="{page}" clickMenu="0" /> {page._thePathFull} + </f:format.raw> + </a> + </td> + </tr> + </f:for> + </tbody> + </table> + </div> + </div> +</f:if> \ No newline at end of file diff --git a/Resources/Private/Templates/Backend/Index.html b/Resources/Private/Templates/Backend/Index.html index 638c13bb366b90b2252d5d1039895d231bcac38f..069938476ca2357df2093e34cee42da9de67f380 100644 --- a/Resources/Private/Templates/Backend/Index.html +++ b/Resources/Private/Templates/Backend/Index.html @@ -1,13 +1,19 @@ <f:layout name="Default" /> -<f:section name="main"> - <ul> - <f:for each="{someData}" as="item" key="itemUid"> - <li> - <f:link.action action="detail" arguments="{itemUid : '{itemUid}'}"> - <f:render partial="ListEntry" arguments="{item : item}" /> - </f:link.action> - </li> - </f:for> - </ul> +<f:section name="iconButtons"> +</f:section> + +<f:section name="headline"> +</f:section> +<f:section name="content"> + <f:debug>{_all}</f:debug> + <f:if condition="{rootPageUid}"> + <f:then> + <h1>test</h1> + </f:then> + + <f:else> + <f:render partial="SelectRoot" arguments="{pages: rootOptions}" /> + </f:else> + </f:if> </f:section>