getCurrentRootPageUid(); // If the current page is not a root page or a subpage of one, abort $pageSelected = ($rootPageUid !== null); $this->view->assign('pageSelected', (int)$pageSelected); if (!$pageSelected) { return; } $this->view->assign('rootPage', $rootPageUid); $this->view->assign('templates', OtPageRepository::templates); $pageRepository = GeneralUtility::makeInstance(OtPageRepository::class); $this->view->assign('currentTemplate', $pageRepository->getCurrentTemplate($rootPageUid)); $this->view->assign('preferences', $pageRepository->getTemplatePreferences($rootPageUid)); $args = $this->request->getArguments(); $this->view->assign('preferencesUpdated', $args['preferencesUpdated']); } /** * A template has been selected, apply the change * */ public function selectTemplateAction() { $templateKey = $this->request->getArgument('template_key'); // Get the current root page's uid $rootPageUid = $this->getCurrentRootPageUid(); // applies the change in the database $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); $queryBuilder->update('pages') ->where( $queryBuilder->expr()->eq( 'uid', $queryBuilder->createNamedParameter($rootPageUid, PDO::PARAM_INT) ) ) ->set('tx_opentalent_template', $templateKey) ->execute() ; // Clear the site's cache CacheManager::clearSiteCache($rootPageUid); CacheManager::clearAssetsTempfiles(); $this->forward('index'); } /** * Update the site's preferences */ public function updatePreferencesAction() { $args = $this->request->getArguments(); $prefs = OtPageRepository::defaultPreferences; if (isset($args['themeColor'])) { $prefs['themeColor'] = $args['themeColor']; } if (isset($args['displayCarousel'])) { $prefs['displayCarousel'] = $args['displayCarousel']; } // Get the current root page's uid $rootPageUid = $this->getCurrentRootPageUid(); // applies the change in the database $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); $queryBuilder->update('pages') ->where( $queryBuilder->expr()->eq( 'uid', $queryBuilder->createNamedParameter($rootPageUid, PDO::PARAM_INT) ) ) ->set('tx_opentalent_template_preferences', json_encode($prefs)) ->execute() ; // Clear the site's cache CacheManager::clearSiteCache($rootPageUid); $this->forward( 'index', 'OtCustomizer', 'OtTemplating', ['preferencesUpdated'=>'1'] ); } /** * Return the uid of the root page of the currently selected * site, or null if no site's page is selected * * @return int | null */ public function getCurrentRootPageUid() { // Get the current page uid $pageId = (int) GeneralUtility::_GP('id'); // Get the root page of the site $otPageRepository = GeneralUtility::makeInstance(OtPageRepository::class); $rootPage = $otPageRepository->getRootPageFor($pageId); if (!$rootPage['uid'] > 0) { return null; } return (int)$rootPage['uid']; } /** * Gets the backend user * * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication */ protected function getBackendUser() { return $GLOBALS['BE_USER']; } }