moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class); $GLOBALS['SOBE'] = $this; $this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_misc.xlf'); $this->init(); } /** * Constructor function for the class */ protected function init() { $beUser = $this->getBackendUserAuthentication(); // Page-selection permission clause (reading) $this->perms_clause = $beUser->getPagePermsClause(Permission::PAGE_SHOW); // This will hide records from display - it has nothing to do with user rights!! if ($pidList = $beUser->getTSConfigVal('options.hideRecords.pages')) { if (!empty($pidList)) { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) ->getQueryBuilderForTable('pages'); $this->perms_clause .= ' AND ' . $queryBuilder->expr()->notIn( 'pages.uid', GeneralUtility::intExplode(',', $pidList) ); } } // Setting GPvars: // The page id to operate from $this->id = (int)GeneralUtility::_GP('id'); $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl')); $this->pagesOnly = GeneralUtility::_GP('pagesOnly'); // Setting up the context sensitive menu: $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu'); $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip'); $this->moduleTemplate->getPageRenderer()->loadRequireJsModule( 'TYPO3/CMS/Backend/Wizard/NewContentElement', 'function(NewContentElement) { require([\'jquery\'], function($) { $(function() { $(\'.t3js-toggle-new-content-element-wizard\').click(function() { var $me = $(this); NewContentElement.wizard($me.data(\'url\'), $me.data(\'title\')); }); }); }); }' ); // Creating content $this->content = ''; $this->content .= '

' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:db_new.php.pagetitle') . '

'; // Id a positive id is supplied, ask for the page record with permission information contained: if ($this->id > 0) { $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause); } // If a page-record was returned, the user had read-access to the page. if ($this->pageinfo['uid']) { // Get record of parent page $this->pidInfo = BackendUtility::getRecord('pages', $this->pageinfo['pid']); // Checking the permissions for the user with regard to the parent page: Can he create new pages, new // content record, new page after? if ($beUser->doesUserHaveAccess($this->pageinfo, 8)) { $this->newPagesInto = 1; } if ($beUser->doesUserHaveAccess($this->pageinfo, 16)) { $this->newContentInto = 1; } if (($beUser->isAdmin() || is_array($this->pidInfo)) && $beUser->doesUserHaveAccess($this->pidInfo, 8)) { $this->newPagesAfter = 1; } } elseif ($beUser->isAdmin()) { // Admins can do it all $this->newPagesInto = 1; $this->newContentInto = 1; $this->newPagesAfter = 0; } else { // People with no permission can do nothing $this->newPagesInto = 0; $this->newContentInto = 0; $this->newPagesAfter = 0; } } /** * Injects the request object for the current request or subrequest * As this controller goes only through the main() method, it is rather simple for now * * @param ServerRequestInterface $request the current request * @param ResponseInterface $response * @return ResponseInterface the response with the content */ public function mainAction(ServerRequestInterface $request, ResponseInterface $response) { $this->main(); $response->getBody()->write($this->moduleTemplate->renderContent()); return $response; } /** * Main processing, creating the list of new record tables to select from */ public function main() { // If there was a page - or if the user is admin (admins has access to the root) we proceed: if (!empty($this->pageinfo['uid']) || $this->getBackendUserAuthentication()->isAdmin()) { if (empty($this->pageinfo)) { // Explicitly pass an empty array to the docHeader $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation([]); } else { $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo); } // Acquiring TSconfig for this module/current page: $this->web_list_modTSconfig = BackendUtility::getModTSconfig($this->pageinfo['uid'], 'mod.web_list'); $this->allowedNewTables = GeneralUtility::trimExplode( ',', $this->web_list_modTSconfig['properties']['allowedNewTables'], true ); $this->deniedNewTables = GeneralUtility::trimExplode( ',', $this->web_list_modTSconfig['properties']['deniedNewTables'], true ); // Acquiring TSconfig for this module/parent page: $this->web_list_modTSconfig_pid = BackendUtility::getModTSconfig($this->pageinfo['pid'], 'mod.web_list'); $this->allowedNewTables_pid = GeneralUtility::trimExplode( ',', $this->web_list_modTSconfig_pid['properties']['allowedNewTables'], true ); $this->deniedNewTables_pid = GeneralUtility::trimExplode( ',', $this->web_list_modTSconfig_pid['properties']['deniedNewTables'], true ); // More init: if (!$this->showNewRecLink('pages')) { $this->newPagesInto = 0; } if (!$this->showNewRecLink('pages', $this->allowedNewTables_pid, $this->deniedNewTables_pid)) { $this->newPagesAfter = 0; } // Set header-HTML and return_url if (is_array($this->pageinfo) && $this->pageinfo['uid']) { $title = strip_tags($this->pageinfo[$GLOBALS['TCA']['pages']['ctrl']['label']]); } else { $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']; } $this->moduleTemplate->setTitle($title); // GENERATE the HTML-output depending on mode (pagesOnly is the page wizard) // Regular new element: if (!$this->pagesOnly) { $this->regularNew(); } elseif ($this->showNewRecLink('pages')) { // Pages only wizard $this->pagesOnly(); } // Add all the content to an output section $this->content .= '
' . $this->code . '
'; // Setting up the buttons and markers for docheader $this->getButtons(); // Build the for the module $this->moduleTemplate->setContent($this->content); } } /** * Create the panel of buttons for submitting the form or otherwise perform operations. */ protected function getButtons() { $lang = $this->getLanguageService(); $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar(); // Regular new element: if (!$this->pagesOnly) { // New page if ($this->showNewRecLink('pages')) { $newPageButton = $buttonBar->makeLinkButton() ->setHref(GeneralUtility::linkThisScript(['pagesOnly' => '1'])) ->setTitle($lang->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newPage')) ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-page-new', Icon::SIZE_SMALL)); $buttonBar->addButton($newPageButton, ButtonBar::BUTTON_POSITION_LEFT, 20); } // CSH $cshButton = $buttonBar->makeHelpButton()->setModuleName('xMOD_csh_corebe')->setFieldName('new_regular'); $buttonBar->addButton($cshButton); } elseif ($this->showNewRecLink('pages')) { // Pages only wizard // CSH $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'new_pages'); $cshButton = $buttonBar->makeHelpButton()->setModuleName('xMOD_csh_corebe')->setFieldName('new_pages'); $buttonBar->addButton($cshButton); } // Back if ($this->returnUrl) { $returnButton = $buttonBar->makeLinkButton() ->setHref($this->returnUrl) ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.goBack')) ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL)); $buttonBar->addButton($returnButton, ButtonBar::BUTTON_POSITION_LEFT, 10); } if (is_array($this->pageinfo) && $this->pageinfo['uid']) { // View $pagesTSconfig = BackendUtility::getPagesTSconfig($this->pageinfo['uid']); if (isset($pagesTSconfig['TCEMAIN.']['preview.']['disableButtonForDokType'])) { $excludeDokTypes = GeneralUtility::intExplode( ',', $pagesTSconfig['TCEMAIN.']['preview.']['disableButtonForDokType'], true ); } else { // exclude sysfolders and recycler by default $excludeDokTypes = [ PageRepository::DOKTYPE_RECYCLER, PageRepository::DOKTYPE_SYSFOLDER, PageRepository::DOKTYPE_SPACER ]; } if (!in_array((int)$this->pageinfo['doktype'], $excludeDokTypes, true)) { $viewButton = $buttonBar->makeLinkButton() ->setHref('#') ->setOnClick(BackendUtility::viewOnClick( $this->pageinfo['uid'], '', BackendUtility::BEgetRootLine($this->pageinfo['uid']) )) ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage')) ->setIcon($this->moduleTemplate->getIconFactory()->getIcon( 'actions-view-page', Icon::SIZE_SMALL )); $buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 30); } } } /** * Creates the position map for pages wizard */ public function pagesOnly() { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) ->getQueryBuilderForTable('sys_language'); $queryBuilder->getRestrictions() ->removeAll() ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); $numberOfPages = $queryBuilder ->count('*') ->from('pages') ->execute() ->fetchColumn(0); if ($numberOfPages > 0) { $this->code .= '

' . htmlspecialchars($this->getLanguageService()->getLL('selectPosition')) . ':

'; $positionMap = GeneralUtility::makeInstance(PagePositionMap::class, NewRecordPageTreeView::class); /** @var $positionMap \TYPO3\CMS\Backend\Tree\View\PagePositionMap */ $this->code .= $positionMap->positionTree( $this->id, $this->pageinfo, $this->perms_clause, $this->returnUrl ); } else { /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */ $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class); // No pages yet, no need to prompt for position, redirect to page creation. $urlParameters = [ 'edit' => [ 'pages' => [ 0 => 'new' ] ], 'returnNewPageId' => 1, 'returnUrl' => (string)$uriBuilder->buildUriFromRoute('db_new', ['id' => $this->id, 'pagesOnly' => '1']) ]; $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters); @ob_end_clean(); HttpUtility::redirect($url); } } /** * Create a regular new element (pages and records) */ public function regularNew() { $lang = $this->getLanguageService(); // Initialize array for accumulating table rows: $this->tRows = []; // Get TSconfig for current page $pageTS = BackendUtility::getPagesTSconfig($this->id); // Finish initializing new pages options with TSconfig // Each new page option may be hidden by TSconfig // Enabled option for the position of a new page $this->newPagesSelectPosition = !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageSelectPosition']); // Pseudo-boolean (0/1) for backward compatibility $displayNewPagesIntoLink = $this->newPagesInto && !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageInside']); $displayNewPagesAfterLink = $this->newPagesAfter && !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageAfter']); // Slight spacer from header: $this->code .= ''; // New Page $table = 'pages'; $v = $GLOBALS['TCA'][$table]; $pageIcon = $this->moduleTemplate->getIconFactory()->getIconForRecord( $table, [], Icon::SIZE_SMALL )->render(); $newPageIcon = $this->moduleTemplate->getIconFactory()->getIcon('actions-page-new', Icon::SIZE_SMALL)->render(); $rowContent = ''; // New pages INSIDE this pages $newPageLinks = []; if ($displayNewPagesIntoLink && $this->isTableAllowedForThisPage($this->pageinfo, 'pages') && $this->getBackendUserAuthentication()->check('tables_modify', 'pages') && $this->getBackendUserAuthentication()->workspaceCreateNewRecord(($this->pageinfo['_ORIG_uid'] ?: $this->id), 'pages') ) { // Create link to new page inside: $recordIcon = $this->moduleTemplate->getIconFactory()->getIconForRecord($table, [], Icon::SIZE_SMALL)->render(); $newPageLinks[] = $this->linkWrap( $recordIcon . htmlspecialchars($lang->sL($v['ctrl']['title'])) . ' (' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:db_new.php.inside')) . ')', $table, $this->id ); } // New pages AFTER this pages if ($displayNewPagesAfterLink && $this->isTableAllowedForThisPage($this->pidInfo, 'pages') && $this->getBackendUserAuthentication()->check('tables_modify', 'pages') && $this->getBackendUserAuthentication()->workspaceCreateNewRecord($this->pidInfo['uid'], 'pages') ) { $newPageLinks[] = $this->linkWrap($pageIcon . htmlspecialchars($lang->sL($v['ctrl']['title'])) . ' (' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:db_new.php.after')) . ')', 'pages', -$this->id); } // New pages at selection position if ($this->newPagesSelectPosition && $this->showNewRecLink('pages')) { // Link to page-wizard: $newPageLinks[] = '' . $pageIcon . htmlspecialchars($lang->getLL('pageSelectPosition')) . ''; } // Assemble all new page links $numPageLinks = count($newPageLinks); for ($i = 0; $i < $numPageLinks; $i++) { $rowContent .= '
  • ' . $newPageLinks[$i] . '
  • '; } if ($this->showNewRecLink('pages')) { $rowContent = '