2 namespace TYPO3\CMS\Backend\Controller
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use Psr\Http\Message\ResponseInterface
;
18 use Psr\Http\Message\ServerRequestInterface
;
19 use TYPO3\CMS\Backend\Routing\UriBuilder
;
20 use TYPO3\CMS\Backend\Template\Components\ButtonBar
;
21 use TYPO3\CMS\Backend\Template\ModuleTemplate
;
22 use TYPO3\CMS\Backend\Tree\View\NewRecordPageTreeView
;
23 use TYPO3\CMS\Backend\Tree\View\PagePositionMap
;
24 use TYPO3\CMS\Backend\Utility\BackendUtility
;
25 use TYPO3\CMS\Core\Database\ConnectionPool
;
26 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
;
27 use TYPO3\CMS\Core\Imaging\Icon
;
28 use TYPO3\CMS\Core\Type\Bitmask\Permission
;
29 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility
;
30 use TYPO3\CMS\Core\Utility\GeneralUtility
;
31 use TYPO3\CMS\Core\Utility\HttpUtility
;
32 use TYPO3\CMS\Core\Utility\PathUtility
;
33 use TYPO3\CMS\Frontend\Page\PageRepository
;
36 * Script class for 'db_new'
38 class NewRecordController
53 protected $newRecordSortList;
63 public $newContentInto;
68 public $newPagesAfter;
71 * Determines, whether "Select Position" for new page should be shown
75 protected $newPagesSelectPosition = true;
80 public $web_list_modTSconfig;
85 public $allowedNewTables;
90 public $deniedNewTables;
95 public $web_list_modTSconfig_pid;
100 public $allowedNewTables_pid;
105 public $deniedNewTables_pid;
137 public $perms_clause;
140 * Accumulated HTML output
152 * ModuleTemplate object
154 * @var ModuleTemplate
156 protected $moduleTemplate;
161 public function __construct()
163 $this->moduleTemplate
= GeneralUtility
::makeInstance(ModuleTemplate
::class);
164 $GLOBALS['SOBE'] = $this;
165 $this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_misc.xlf');
170 * Constructor function for the class
172 protected function init()
174 $beUser = $this->getBackendUserAuthentication();
175 // Page-selection permission clause (reading)
176 $this->perms_clause
= $beUser->getPagePermsClause(Permission
::PAGE_SHOW
);
177 // This will hide records from display - it has nothing to do with user rights!!
178 if ($pidList = $beUser->getTSConfigVal('options.hideRecords.pages')) {
179 if (!empty($pidList)) {
180 $queryBuilder = GeneralUtility
::makeInstance(ConnectionPool
::class)
181 ->getQueryBuilderForTable('pages');
182 $this->perms_clause
.= ' AND ' . $queryBuilder->expr()->notIn(
184 GeneralUtility
::intExplode(',', $pidList)
189 // The page id to operate from
190 $this->id
= (int)GeneralUtility
::_GP('id');
191 $this->returnUrl
= GeneralUtility
::sanitizeLocalUrl(GeneralUtility
::_GP('returnUrl'));
192 $this->pagesOnly
= GeneralUtility
::_GP('pagesOnly');
193 // Setting up the context sensitive menu:
194 $this->moduleTemplate
->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
195 $this->moduleTemplate
->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
196 $this->moduleTemplate
->getPageRenderer()->loadRequireJsModule(
197 'TYPO3/CMS/Backend/Wizard/NewContentElement',
198 'function(NewContentElement) {
199 require([\'jquery\'], function($) {
201 $(\'.t3js-toggle-new-content-element-wizard\').click(function() {
203 NewContentElement.wizard($me.data(\'url\'), $me.data(\'title\'));
211 $this->content
.= '<h1>'
212 . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:db_new.php.pagetitle')
214 // Id a positive id is supplied, ask for the page record with permission information contained:
216 $this->pageinfo
= BackendUtility
::readPageAccess($this->id
, $this->perms_clause
);
218 // If a page-record was returned, the user had read-access to the page.
219 if ($this->pageinfo
['uid']) {
220 // Get record of parent page
221 $this->pidInfo
= BackendUtility
::getRecord('pages', $this->pageinfo
['pid']);
222 // Checking the permissions for the user with regard to the parent page: Can he create new pages, new
223 // content record, new page after?
224 if ($beUser->doesUserHaveAccess($this->pageinfo
, 8)) {
225 $this->newPagesInto
= 1;
227 if ($beUser->doesUserHaveAccess($this->pageinfo
, 16)) {
228 $this->newContentInto
= 1;
230 if (($beUser->isAdmin() ||
is_array($this->pidInfo
)) && $beUser->doesUserHaveAccess($this->pidInfo
, 8)) {
231 $this->newPagesAfter
= 1;
233 } elseif ($beUser->isAdmin()) {
234 // Admins can do it all
235 $this->newPagesInto
= 1;
236 $this->newContentInto
= 1;
237 $this->newPagesAfter
= 0;
239 // People with no permission can do nothing
240 $this->newPagesInto
= 0;
241 $this->newContentInto
= 0;
242 $this->newPagesAfter
= 0;
247 * Injects the request object for the current request or subrequest
248 * As this controller goes only through the main() method, it is rather simple for now
250 * @param ServerRequestInterface $request the current request
251 * @param ResponseInterface $response
252 * @return ResponseInterface the response with the content
254 public function mainAction(ServerRequestInterface
$request, ResponseInterface
$response)
258 $response->getBody()->write($this->moduleTemplate
->renderContent());
263 * Main processing, creating the list of new record tables to select from
265 public function main()
267 // If there was a page - or if the user is admin (admins has access to the root) we proceed:
268 if (!empty($this->pageinfo
['uid']) ||
$this->getBackendUserAuthentication()->isAdmin()) {
269 if (empty($this->pageinfo
)) {
270 // Explicitly pass an empty array to the docHeader
271 $this->moduleTemplate
->getDocHeaderComponent()->setMetaInformation([]);
273 $this->moduleTemplate
->getDocHeaderComponent()->setMetaInformation($this->pageinfo
);
275 // Acquiring TSconfig for this module/current page:
276 $this->web_list_modTSconfig
= BackendUtility
::getModTSconfig($this->pageinfo
['uid'], 'mod.web_list');
277 $this->allowedNewTables
= GeneralUtility
::trimExplode(
279 $this->web_list_modTSconfig
['properties']['allowedNewTables'],
282 $this->deniedNewTables
= GeneralUtility
::trimExplode(
284 $this->web_list_modTSconfig
['properties']['deniedNewTables'],
287 // Acquiring TSconfig for this module/parent page:
288 $this->web_list_modTSconfig_pid
= BackendUtility
::getModTSconfig($this->pageinfo
['pid'], 'mod.web_list');
289 $this->allowedNewTables_pid
= GeneralUtility
::trimExplode(
291 $this->web_list_modTSconfig_pid
['properties']['allowedNewTables'],
294 $this->deniedNewTables_pid
= GeneralUtility
::trimExplode(
296 $this->web_list_modTSconfig_pid
['properties']['deniedNewTables'],
300 if (!$this->showNewRecLink('pages')) {
301 $this->newPagesInto
= 0;
303 if (!$this->showNewRecLink('pages', $this->allowedNewTables_pid
, $this->deniedNewTables_pid
)) {
304 $this->newPagesAfter
= 0;
306 // Set header-HTML and return_url
307 if (is_array($this->pageinfo
) && $this->pageinfo
['uid']) {
308 $title = strip_tags($this->pageinfo
[$GLOBALS['TCA']['pages']['ctrl']['label']]);
310 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
312 $this->moduleTemplate
->setTitle($title);
313 // GENERATE the HTML-output depending on mode (pagesOnly is the page wizard)
314 // Regular new element:
315 if (!$this->pagesOnly
) {
317 } elseif ($this->showNewRecLink('pages')) {
321 // Add all the content to an output section
322 $this->content
.= '<div>' . $this->code
. '</div>';
323 // Setting up the buttons and markers for docheader
325 // Build the <body> for the module
326 $this->moduleTemplate
->setContent($this->content
);
331 * Create the panel of buttons for submitting the form or otherwise perform operations.
333 protected function getButtons()
335 $lang = $this->getLanguageService();
336 $buttonBar = $this->moduleTemplate
->getDocHeaderComponent()->getButtonBar();
337 // Regular new element:
338 if (!$this->pagesOnly
) {
340 if ($this->showNewRecLink('pages')) {
341 $newPageButton = $buttonBar->makeLinkButton()
342 ->setHref(GeneralUtility
::linkThisScript(['pagesOnly' => '1']))
343 ->setTitle($lang->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newPage'))
344 ->setIcon($this->moduleTemplate
->getIconFactory()->getIcon('actions-page-new', Icon
::SIZE_SMALL
));
345 $buttonBar->addButton($newPageButton, ButtonBar
::BUTTON_POSITION_LEFT
, 20);
348 $cshButton = $buttonBar->makeHelpButton()->setModuleName('xMOD_csh_corebe')->setFieldName('new_regular');
349 $buttonBar->addButton($cshButton);
350 } elseif ($this->showNewRecLink('pages')) {
353 $buttons['csh'] = BackendUtility
::cshItem('xMOD_csh_corebe', 'new_pages');
354 $cshButton = $buttonBar->makeHelpButton()->setModuleName('xMOD_csh_corebe')->setFieldName('new_pages');
355 $buttonBar->addButton($cshButton);
358 if ($this->returnUrl
) {
359 $returnButton = $buttonBar->makeLinkButton()
360 ->setHref($this->returnUrl
)
361 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
362 ->setIcon($this->moduleTemplate
->getIconFactory()->getIcon('actions-view-go-back', Icon
::SIZE_SMALL
));
363 $buttonBar->addButton($returnButton, ButtonBar
::BUTTON_POSITION_LEFT
, 10);
366 if (is_array($this->pageinfo
) && $this->pageinfo
['uid']) {
368 $pagesTSconfig = BackendUtility
::getPagesTSconfig($this->pageinfo
['uid']);
369 if (isset($pagesTSconfig['TCEMAIN.']['preview.']['disableButtonForDokType'])) {
370 $excludeDokTypes = GeneralUtility
::intExplode(
372 $pagesTSconfig['TCEMAIN.']['preview.']['disableButtonForDokType'],
376 // exclude sysfolders and recycler by default
378 PageRepository
::DOKTYPE_RECYCLER
,
379 PageRepository
::DOKTYPE_SYSFOLDER
,
380 PageRepository
::DOKTYPE_SPACER
383 if (!in_array((int)$this->pageinfo
['doktype'], $excludeDokTypes, true)) {
384 $viewButton = $buttonBar->makeLinkButton()
386 ->setOnClick(BackendUtility
::viewOnClick(
387 $this->pageinfo
['uid'],
389 BackendUtility
::BEgetRootLine($this->pageinfo
['uid'])
391 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
392 ->setIcon($this->moduleTemplate
->getIconFactory()->getIcon(
396 $buttonBar->addButton($viewButton, ButtonBar
::BUTTON_POSITION_LEFT
, 30);
402 * Creates the position map for pages wizard
404 public function pagesOnly()
406 $queryBuilder = GeneralUtility
::makeInstance(ConnectionPool
::class)
407 ->getQueryBuilderForTable('sys_language');
408 $queryBuilder->getRestrictions()
410 ->add(GeneralUtility
::makeInstance(DeletedRestriction
::class));
411 $numberOfPages = $queryBuilder
417 if ($numberOfPages > 0) {
418 $this->code
.= '<h3>' . htmlspecialchars($this->getLanguageService()->getLL('selectPosition')) . ':</h3>';
419 $positionMap = GeneralUtility
::makeInstance(PagePositionMap
::class, NewRecordPageTreeView
::class);
420 /** @var $positionMap \TYPO3\CMS\Backend\Tree\View\PagePositionMap */
421 $this->code
.= $positionMap->positionTree(
428 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
429 $uriBuilder = GeneralUtility
::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder
::class);
430 // No pages yet, no need to prompt for position, redirect to page creation.
437 'returnNewPageId' => 1,
438 'returnUrl' => (string)$uriBuilder->buildUriFromRoute('db_new', ['id' => $this->id
, 'pagesOnly' => '1'])
440 $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
442 HttpUtility
::redirect($url);
447 * Create a regular new element (pages and records)
449 public function regularNew()
451 $lang = $this->getLanguageService();
452 // Initialize array for accumulating table rows:
454 // Get TSconfig for current page
455 $pageTS = BackendUtility
::getPagesTSconfig($this->id
);
456 // Finish initializing new pages options with TSconfig
457 // Each new page option may be hidden by TSconfig
458 // Enabled option for the position of a new page
459 $this->newPagesSelectPosition
= !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageSelectPosition']);
460 // Pseudo-boolean (0/1) for backward compatibility
461 $displayNewPagesIntoLink = $this->newPagesInto
&& !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageInside']);
462 $displayNewPagesAfterLink = $this->newPagesAfter
&& !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageAfter']);
463 // Slight spacer from header:
467 $v = $GLOBALS['TCA'][$table];
468 $pageIcon = $this->moduleTemplate
->getIconFactory()->getIconForRecord(
473 $newPageIcon = $this->moduleTemplate
->getIconFactory()->getIcon('actions-page-new', Icon
::SIZE_SMALL
)->render();
475 // New pages INSIDE this pages
477 if ($displayNewPagesIntoLink
478 && $this->isTableAllowedForThisPage($this->pageinfo
, 'pages')
479 && $this->getBackendUserAuthentication()->check('tables_modify', 'pages')
480 && $this->getBackendUserAuthentication()->workspaceCreateNewRecord(($this->pageinfo
['_ORIG_uid'] ?
: $this->id
), 'pages')
482 // Create link to new page inside:
483 $recordIcon = $this->moduleTemplate
->getIconFactory()->getIconForRecord($table, [], Icon
::SIZE_SMALL
)->render();
484 $newPageLinks[] = $this->linkWrap(
485 $recordIcon . htmlspecialchars($lang->sL($v['ctrl']['title'])) . ' (' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:db_new.php.inside')) . ')',
490 // New pages AFTER this pages
491 if ($displayNewPagesAfterLink
492 && $this->isTableAllowedForThisPage($this->pidInfo
, 'pages')
493 && $this->getBackendUserAuthentication()->check('tables_modify', 'pages')
494 && $this->getBackendUserAuthentication()->workspaceCreateNewRecord($this->pidInfo
['uid'], 'pages')
496 $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
);
498 // New pages at selection position
499 if ($this->newPagesSelectPosition
&& $this->showNewRecLink('pages')) {
500 // Link to page-wizard:
501 $newPageLinks[] = '<a href="' . htmlspecialchars(GeneralUtility
::linkThisScript(['pagesOnly' => 1])) . '">' . $pageIcon . htmlspecialchars($lang->getLL('pageSelectPosition')) . '</a>';
503 // Assemble all new page links
504 $numPageLinks = count($newPageLinks);
505 for ($i = 0; $i < $numPageLinks; $i++
) {
506 $rowContent .= '<li>' . $newPageLinks[$i] . '</li>';
508 if ($this->showNewRecLink('pages')) {
509 $rowContent = '<ul class="list-tree"><li>' . $newPageIcon . '<strong>' .
510 $lang->getLL('createNewPage') . '</strong><ul>' . $rowContent . '</ul></li>';
512 $rowContent = '<ul class="list-tree"><li><ul>' . $rowContent . '</li></ul>';
514 /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
515 $uriBuilder = GeneralUtility
::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder
::class);
517 $startRows = [$rowContent];
519 // New tables (but not pages) INSIDE this pages
520 $isAdmin = $this->getBackendUserAuthentication()->isAdmin();
521 $newContentIcon = $this->moduleTemplate
->getIconFactory()->getIcon('actions-document-new', Icon
::SIZE_SMALL
)->render();
522 if ($this->newContentInto
) {
523 if (is_array($GLOBALS['TCA'])) {
525 foreach ($GLOBALS['TCA'] as $table => $v) {
526 $rootLevelConfiguration = isset($v['ctrl']['rootLevel']) ?
(int)$v['ctrl']['rootLevel'] : 0;
527 if ($table !== 'pages'
528 && $this->showNewRecLink($table)
529 && $this->isTableAllowedForThisPage($this->pageinfo
, $table)
530 && $this->getBackendUserAuthentication()->check('tables_modify', $table)
531 && ($rootLevelConfiguration === -1 ||
($this->id
xor $rootLevelConfiguration))
532 && $this->getBackendUserAuthentication()->workspaceCreateNewRecord(($this->pageinfo
['_ORIG_uid'] ?
$this->pageinfo
['_ORIG_uid'] : $this->id
), $table)
534 $newRecordIcon = $this->moduleTemplate
->getIconFactory()->getIconForRecord($table, [], Icon
::SIZE_SMALL
)->render();
537 // Create new link for record:
538 $newLink = $this->linkWrap($newRecordIcon . htmlspecialchars($lang->sL($v['ctrl']['title'])), $table, $this->id
);
539 // If the table is 'tt_content', create link to wizard
540 if ($table === 'tt_content') {
541 $groupName = $lang->getLL('createNewContent');
542 $rowContent = $newContentIcon
543 . '<strong>' . $lang->getLL('createNewContent') . '</strong>'
545 // If mod.newContentElementWizard.override is set, use that extension's wizard instead:
546 $tsConfig = BackendUtility
::getModTSconfig($this->id
, 'mod');
547 $moduleName = isset($tsConfig['properties']['newContentElementWizard.']['override'])
548 ?
$tsConfig['properties']['newContentElementWizard.']['override']
549 : 'new_content_element_wizard';
550 $url = (string)$uriBuilder->buildUriFromRoute($moduleName, ['id' => $this->id
, 'returnUrl' => GeneralUtility
::getIndpEnv('REQUEST_URI')]);
551 $rowContent .= '<li>' . $newLink . ' ' . BackendUtility
::wrapInHelp($table, '') . '</li>'
553 . '<a href="#" data-url="' . htmlspecialchars($url) . '" data-title="' . htmlspecialchars($this->getLanguageService()->getLL('newContentElement')) . '" class="t3js-toggle-new-content-element-wizard">'
554 . $newContentIcon . htmlspecialchars($lang->getLL('clickForWizard'))
560 if ($v['ctrl']['readOnly'] ||
$v['ctrl']['hideTable'] ||
$v['ctrl']['is_static']) {
563 if ($v['ctrl']['adminOnly'] && !$isAdmin) {
566 $nameParts = explode('_', $table);
569 if ($nameParts[0] === 'tx' ||
$nameParts[0] === 'tt') {
570 // Try to extract extension name
571 if (substr($v['ctrl']['title'], 0, 8) === 'LLL:EXT:') {
572 $_EXTKEY = substr($v['ctrl']['title'], 8);
573 $_EXTKEY = substr($_EXTKEY, 0, strpos($_EXTKEY, '/'));
574 if ($_EXTKEY !== '') {
575 // First try to get localisation of extension title
576 $temp = explode(':', substr($v['ctrl']['title'], 9 +
strlen($_EXTKEY)));
577 $langFile = $temp[0];
578 $thisTitle = $lang->sL('LLL:EXT:' . $_EXTKEY . '/' . $langFile . ':extension.title');
579 // If no localisation available, read title from ext_emconf.php
580 $extPath = ExtensionManagementUtility
::extPath($_EXTKEY);
581 $extEmConfFile = $extPath . 'ext_emconf.php';
582 if (!$thisTitle && is_file($extEmConfFile)) {
584 include $extEmConfFile;
585 $thisTitle = $EM_CONF[$_EXTKEY]['title'];
587 $iconFile[$_EXTKEY] = '<img src="' . PathUtility
::getAbsoluteWebPath(ExtensionManagementUtility
::getExtensionIcon($extPath, true)) . '" ' . 'width="16" height="16" ' . 'alt="' . $thisTitle . '" />';
590 if (empty($thisTitle)) {
591 $_EXTKEY = $nameParts[1];
592 $thisTitle = $nameParts[1];
593 $iconFile[$_EXTKEY] = '';
597 $thisTitle = $lang->getLL('system_records');
598 $iconFile['system'] = $this->moduleTemplate
->getIconFactory()->getIcon('apps-pagetree-root', Icon
::SIZE_SMALL
)->render();
601 if ($groupName === '' ||
$groupName !== $_EXTKEY) {
602 $groupName = empty($v['ctrl']['groupName']) ?
$_EXTKEY : $v['ctrl']['groupName'];
604 $rowContent .= $newLink;
606 // Compile table row:
607 if ($table === 'tt_content') {
608 $startRows[] = '<li>' . $rowContent . '</li>';
610 $this->tRows
[$groupName]['title'] = $thisTitle;
611 $this->tRows
[$groupName]['html'][] = $rowContent;
612 $this->tRows
[$groupName]['table'][] = $table;
619 if (isset($pageTS['mod.']['wizards.']['newRecord.']['order'])) {
620 $this->newRecordSortList
= GeneralUtility
::trimExplode(',', $pageTS['mod.']['wizards.']['newRecord.']['order'], true);
622 uksort($this->tRows
, [$this, 'sortNewRecordsByConfig']);
623 // Compile table row:
625 $finalRows[] = implode('', $startRows);
626 foreach ($this->tRows
as $key => $value) {
627 $row = '<li>' . $iconFile[$key] . ' <strong>' . $value['title'] . '</strong><ul>';
628 foreach ($value['html'] as $recordKey => $record) {
629 $row .= '<li>' . $record . ' ' . BackendUtility
::wrapInHelp($value['table'][$recordKey], '') . '</li>';
631 $row .= '</ul></li>';
635 $finalRows[] = '</ul>';
637 $this->code
.= implode('', $finalRows);
641 * User array sort function used by regularNew
643 * @param string $a First array element for compare
644 * @param string $b First array element for compare
645 * @return int -1 for lower, 0 for equal, 1 for greater
647 public function sortNewRecordsByConfig($a, $b)
649 if (!empty($this->newRecordSortList
)) {
650 if (in_array($a, $this->newRecordSortList
) && in_array($b, $this->newRecordSortList
)) {
651 // Both are in the list, return relative to position in array
652 $sub = array_search($a, $this->newRecordSortList
) - array_search($b, $this->newRecordSortList
);
653 $ret = ($sub < 0 ?
-1 : $sub == 0) ?
0 : 1;
654 } elseif (in_array($a, $this->newRecordSortList
)) {
655 // First element is in array, put to top
657 } elseif (in_array($b, $this->newRecordSortList
)) {
658 // Second element is in array, put first to bottom
661 // No element is in array, return alphabetic order
662 $ret = strnatcasecmp($this->tRows
[$a]['title'], $this->tRows
[$b]['title']);
666 // Return alphabetic order
667 return strnatcasecmp($this->tRows
[$a]['title'], $this->tRows
[$b]['title']);
671 * Links the string $code to a create-new form for a record in $table created on page $pid
673 * @param string $linkText Link text
674 * @param string $table Table name (in which to create new record)
675 * @param int $pid PID value for the "&edit['.$table.']['.$pid.']=new" command (positive/negative)
676 * @param bool $addContentTable If $addContentTable is set, then a new tt_content record is created together with pages
677 * @return string The link.
679 public function linkWrap($linkText, $table, $pid, $addContentTable = false)
687 'returnUrl' => $this->returnUrl
689 if ($table === 'pages' && $addContentTable) {
690 $urlParameters['tt_content']['prev'] = 'new';
691 $urlParameters['returnNewPageId'] = 1;
692 } elseif ($table === 'pages') {
693 $urlParameters['overrideVals']['pages']['doktype'] = (int)$this->pageinfo
['doktype'];
695 $uriBuilder = GeneralUtility
::makeInstance(UriBuilder
::class);
696 $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
697 return '<a href="' . htmlspecialchars($url) . '">' . $linkText . '</a>';
701 * Returns TRUE if the tablename $checkTable is allowed to be created on the page with record $pid_row
703 * @param array $pid_row Record for parent page.
704 * @param string $checkTable Table name to check
705 * @return bool Returns TRUE if the tablename $checkTable is allowed to be created on the page with record $pid_row
707 public function isTableAllowedForThisPage($pid_row, $checkTable)
709 if (!is_array($pid_row)) {
710 return $this->getBackendUserAuthentication()->isAdmin();
712 // be_users and be_groups may not be created anywhere but in the root.
713 if ($checkTable === 'be_users' ||
$checkTable === 'be_groups') {
717 $doktype = (int)$pid_row['doktype'];
718 if (!($allowedTableList = $GLOBALS['PAGES_TYPES'][$doktype]['allowedTables'])) {
719 $allowedTableList = $GLOBALS['PAGES_TYPES']['default']['allowedTables'];
721 // If all tables or the table is listed as an allowed type, return TRUE
722 if (strstr($allowedTableList, '*') || GeneralUtility
::inList($allowedTableList, $checkTable)) {
731 * - $allowedNewTables and $deniedNewTables are empty
732 * - the table is not found in $deniedNewTables and $allowedNewTables is not set or the $table tablename is found in
735 * If $table tablename is found in $allowedNewTables and $deniedNewTables, $deniedNewTables
736 * has priority over $allowedNewTables.
738 * @param string $table Table name to test if in allowedTables
739 * @param array $allowedNewTables Array of new tables that are allowed.
740 * @param array $deniedNewTables Array of new tables that are not allowed.
742 * @return bool Returns TRUE if a link for creating new records should be displayed for $table
744 public function showNewRecLink($table, array $allowedNewTables = [], array $deniedNewTables = [])
746 if (!$this->getBackendUserAuthentication()->check('tables_modify', $table)) {
750 $allowedNewTables = $allowedNewTables ?
: $this->allowedNewTables
;
751 $deniedNewTables = $deniedNewTables ?
: $this->deniedNewTables
;
752 // No deny/allow tables are set:
753 if (empty($allowedNewTables) && empty($deniedNewTables)) {
757 return !in_array($table, $deniedNewTables) && (empty($allowedNewTables) ||
in_array($table, $allowedNewTables));
761 * Checks if sys_language records are present
765 protected function checkIfLanguagesExist()
767 $queryBuilder = GeneralUtility
::makeInstance(ConnectionPool
::class)
768 ->getQueryBuilderForTable('sys_language');
769 $queryBuilder->getRestrictions()->removeAll();
771 $count = $queryBuilder
773 ->from('sys_language')
780 * Return language service instance
782 * @return \TYPO3\CMS\Core\Localization\LanguageService
784 protected function getLanguageService()
786 return $GLOBALS['LANG'];
790 * Returns the global BackendUserAuthentication object.
792 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
794 protected function getBackendUserAuthentication()
796 return $GLOBALS['BE_USER'];