‪TYPO3CMS  10.4
NewRecordController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
40 
46 {
50  protected ‪$pageinfo = [];
51 
55  protected ‪$pidInfo = [];
56 
60  protected ‪$newRecordSortList;
61 
65  protected ‪$newPagesInto;
66 
70  protected ‪$newContentInto;
71 
75  protected ‪$newPagesAfter;
76 
82  protected ‪$newPagesSelectPosition = true;
83 
88 
92  protected ‪$allowedNewTables;
93 
97  protected ‪$deniedNewTables;
98 
103 
107  protected ‪$allowedNewTables_pid;
108 
112  protected ‪$deniedNewTables_pid;
113 
117  protected ‪$code;
118 
125  public ‪$id;
126 
130  protected ‪$returnUrl;
131 
137  protected ‪$pagesOnly;
138 
142  protected ‪$perms_clause;
143 
149  protected ‪$content;
150 
154  protected ‪$tRows;
155 
161  protected ‪$moduleTemplate;
162 
166  public function ‪__construct()
167  {
168  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
169  $this->‪getLanguageService()->‪includeLLFile('EXT:core/Resources/Private/Language/locallang_misc.xlf');
170  }
171 
179  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
180  {
181  $this->‪init($request);
182  $response = $this->‪renderContent($request);
183 
184  if (empty($response)) {
185  $response = new ‪HtmlResponse($this->moduleTemplate->renderContent());
186  }
187 
188  return $response;
189  }
190 
196  protected function ‪init(ServerRequestInterface $request): void
197  {
198  $beUser = $this->‪getBackendUserAuthentication();
199  // Page-selection permission clause (reading)
200  $this->perms_clause = $beUser->getPagePermsClause(‪Permission::PAGE_SHOW);
201  // This will hide records from display - it has nothing to do with user rights!!
202  $pidList = $beUser->getTSConfig()['options.']['hideRecords.']['pages'] ?? '';
203  if (!empty($pidList)) {
204  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
205  ->getQueryBuilderForTable('pages');
206  $this->perms_clause .= ' AND ' . $queryBuilder->expr()->notIn(
207  'pages.uid',
208  ‪GeneralUtility::intExplode(',', $pidList)
209  );
210  }
211  // Setting GPvars:
212  $parsedBody = $request->getParsedBody();
213  $queryParams = $request->getQueryParams();
214  // The page id to operate from
215  $this->id = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0);
216  $this->returnUrl = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? '');
217  $this->pagesOnly = $parsedBody['pagesOnly'] ?? $queryParams['pagesOnly'] ?? null;
218  // Setting up the context sensitive menu:
219  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
220  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
221  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/PageActions');
222  // Creating content
223  $this->content = '';
224  $this->content .= '<h1>'
225  . $this->‪getLanguageService()->‪sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:db_new.php.pagetitle')
226  . '</h1>';
227  // Id a positive id is supplied, ask for the page record with permission information contained:
228  if ($this->id > 0) {
229  $this->pageinfo = ‪BackendUtility::readPageAccess($this->id, $this->perms_clause);
230  }
231  // If a page-record was returned, the user had read-access to the page.
232  if ($this->pageinfo['uid']) {
233  // Get record of parent page
234  $this->pidInfo = ‪BackendUtility::getRecord('pages', $this->pageinfo['pid']) ?: [];
235  // Checking the permissions for the user with regard to the parent page: Can he create new pages, new
236  // content record, new page after?
237  if ($beUser->doesUserHaveAccess($this->pageinfo, 8)) {
238  $this->newPagesInto = 1;
239  }
240  if ($beUser->doesUserHaveAccess($this->pageinfo, 16)) {
241  $this->newContentInto = 1;
242  }
243  if (($beUser->isAdmin() || !empty($this->pidInfo)) && $beUser->doesUserHaveAccess($this->pidInfo, 8)) {
244  $this->newPagesAfter = 1;
245  }
246  } elseif ($beUser->isAdmin()) {
247  // Admins can do it all
248  $this->newPagesInto = 1;
249  $this->newContentInto = 1;
250  $this->newPagesAfter = 0;
251  } else {
252  // People with no permission can do nothing
253  $this->newPagesInto = 0;
254  $this->newContentInto = 0;
255  $this->newPagesAfter = 0;
256  }
257  }
258 
265  protected function ‪renderContent(ServerRequestInterface $request): ?ResponseInterface
266  {
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([]);
272  } else {
273  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
274  }
275  // Acquiring TSconfig for this module/current page:
276  $this->web_list_modTSconfig = ‪BackendUtility::getPagesTSconfig($this->pageinfo['uid'])['mod.']['web_list.'] ?? [];
277  $this->allowedNewTables = ‪GeneralUtility::trimExplode(',', $this->web_list_modTSconfig['allowedNewTables'] ?? '', true);
278  $this->deniedNewTables = ‪GeneralUtility::trimExplode(',', $this->web_list_modTSconfig['deniedNewTables'] ?? '', true);
279  // Acquiring TSconfig for this module/parent page:
280  $this->web_list_modTSconfig_pid = ‪BackendUtility::getPagesTSconfig($this->pageinfo['pid'])['mod.']['web_list.'] ?? [];
281  $this->allowedNewTables_pid = ‪GeneralUtility::trimExplode(',', $this->web_list_modTSconfig_pid['allowedNewTables'] ?? '', true);
282  $this->deniedNewTables_pid = ‪GeneralUtility::trimExplode(',', $this->web_list_modTSconfig_pid['deniedNewTables'] ?? '', true);
283  // More init:
284  if (!$this->‪isRecordCreationAllowedForTable('pages')) {
285  $this->newPagesInto = 0;
286  }
287  if (!$this->‪isRecordCreationAllowedForTable('pages', $this->allowedNewTables_pid, $this->deniedNewTables_pid)) {
288  $this->newPagesAfter = 0;
289  }
290  // Set header-HTML and return_url
291  if (is_array($this->pageinfo) && $this->pageinfo['uid']) {
292  $title = strip_tags($this->pageinfo[‪$GLOBALS['TCA']['pages']['ctrl']['label']]);
293  } else {
294  $title = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
295  }
296  $this->moduleTemplate->setTitle($title);
297  // GENERATE the HTML-output depending on mode (pagesOnly is the page wizard)
298  // Regular new element:
299  if (!$this->pagesOnly) {
300  $this->‪renderNewRecordControls($request);
301  } elseif ($this->‪isRecordCreationAllowedForTable('pages')) {
302  // Pages only wizard
303  $response = $this->‪renderPositionTree();
304 
305  if (!empty($response)) {
306  return $response;
307  }
308  }
309  // Add all the content to an output section
310  $this->content .= '<div>' . $this->code . '</div>';
311  // Setting up the buttons and markers for docheader
312  $this->‪getButtons();
313  // Build the <body> for the module
314  $this->moduleTemplate->setContent($this->content);
315  }
316 
317  return null;
318  }
319 
323  protected function ‪getButtons(): void
324  {
325  $buttons = [];
326  $lang = $this->‪getLanguageService();
327  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
328  // Regular new element:
329  if (!$this->pagesOnly) {
330  // New page
331  if ($this->‪isRecordCreationAllowedForTable('pages')) {
332  $newPageButton = $buttonBar->makeLinkButton()
333  ->setHref(GeneralUtility::linkThisScript(['pagesOnly' => '1']))
334  ->setTitle($lang->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newPage'))
335  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-page-new', ‪Icon::SIZE_SMALL));
336  $buttonBar->addButton($newPageButton, ‪ButtonBar::BUTTON_POSITION_LEFT, 20);
337  }
338  // CSH
339  $cshButton = $buttonBar->makeHelpButton()->setModuleName('xMOD_csh_corebe')->setFieldName('new_regular');
340  $buttonBar->addButton($cshButton);
341  } elseif ($this->‪isRecordCreationAllowedForTable('pages')) {
342  // Pages only wizard
343  // CSH
344  $buttons['csh'] = ‪BackendUtility::cshItem('xMOD_csh_corebe', 'new_pages');
345  $cshButton = $buttonBar->makeHelpButton()->setModuleName('xMOD_csh_corebe')->setFieldName('new_pages');
346  $buttonBar->addButton($cshButton);
347  }
348  // Back
349  if ($this->returnUrl) {
350  $returnButton = $buttonBar->makeLinkButton()
351  ->setHref($this->returnUrl)
352  ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
353  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', ‪Icon::SIZE_SMALL));
354  $buttonBar->addButton($returnButton, ‪ButtonBar::BUTTON_POSITION_LEFT, 10);
355  }
356 
357  if (is_array($this->pageinfo) && $this->pageinfo['uid']) {
358  // View
359  $pagesTSconfig = ‪BackendUtility::getPagesTSconfig($this->pageinfo['uid']);
360  if (isset($pagesTSconfig['TCEMAIN.']['preview.']['disableButtonForDokType'])) {
361  $excludeDokTypes = ‪GeneralUtility::intExplode(
362  ',',
363  $pagesTSconfig['TCEMAIN.']['preview.']['disableButtonForDokType'],
364  true
365  );
366  } else {
367  // exclude sysfolders and recycler by default
368  $excludeDokTypes = [
372  ];
373  }
374  if (!in_array((int)$this->pageinfo['doktype'], $excludeDokTypes, true)) {
375  $viewButton = $buttonBar->makeLinkButton()
376  ->setHref('#')
377  ->setOnClick(‪BackendUtility::viewOnClick(
378  $this->pageinfo['uid'],
379  '',
380  ‪BackendUtility::BEgetRootLine($this->pageinfo['uid'])
381  ))
382  ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
383  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
384  'actions-view-page',
386  ));
387  $buttonBar->addButton($viewButton, ‪ButtonBar::BUTTON_POSITION_LEFT, 30);
388  }
389  }
390  }
391 
397  protected function ‪renderPositionTree(): ?ResponseInterface
398  {
399  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
400  ->getQueryBuilderForTable('pages');
401  $queryBuilder->getRestrictions()
402  ->removeAll()
403  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
404  $numberOfPages = $queryBuilder
405  ->count('*')
406  ->from('pages')
407  ->execute()
408  ->fetchColumn(0);
409 
410  if ($numberOfPages > 0) {
411  $this->code .= '<h3>' . htmlspecialchars($this->‪getLanguageService()->getLL('selectPosition')) . ':</h3>';
412  $positionMap = GeneralUtility::makeInstance(PagePositionMap::class, NewRecordPageTreeView::class);
413  $this->code .= $positionMap->positionTree(
414  $this->id,
415  $this->pageinfo,
416  $this->perms_clause,
417  $this->returnUrl
418  );
419  } else {
420  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
421  // No pages yet, no need to prompt for position, redirect to page creation.
422  $urlParameters = [
423  'edit' => [
424  'pages' => [
425  0 => 'new'
426  ]
427  ],
428  'returnNewPageId' => 1,
429  'returnUrl' => (string)$uriBuilder->buildUriFromRoute('db_new', ['id' => $this->id, 'pagesOnly' => '1'])
430  ];
431  $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
432  @ob_end_clean();
433 
434  return new ‪RedirectResponse($url);
435  }
436 
437  return null;
438  }
439 
445  protected function ‪renderNewRecordControls(ServerRequestInterface $request): void
446  {
447  $lang = $this->‪getLanguageService();
448  // Initialize array for accumulating table rows:
449  $this->tRows = [];
450  // Get TSconfig for current page
451  $pageTS = ‪BackendUtility::getPagesTSconfig($this->id);
452  // Finish initializing new pages options with TSconfig
453  // Each new page option may be hidden by TSconfig
454  // Enabled option for the position of a new page
455  $this->newPagesSelectPosition = !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageSelectPosition']);
456  // Pseudo-boolean (0/1) for backward compatibility
457  $displayNewPagesIntoLink = $this->newPagesInto && !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageInside']);
458  $displayNewPagesAfterLink = $this->newPagesAfter && !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageAfter']);
459  // Slight spacer from header:
460  $this->code .= '';
461  // New Page
462  $table = 'pages';
463  $v = ‪$GLOBALS['TCA'][$table];
464  $pageIcon = $this->moduleTemplate->getIconFactory()->getIconForRecord(
465  $table,
466  [],
468  )->render();
469  $newPageIcon = $this->moduleTemplate->getIconFactory()->getIcon('actions-page-new', ‪Icon::SIZE_SMALL)->render();
470  $rowContent = '';
471  // New pages INSIDE this pages
472  $newPageLinks = [];
473  if ($displayNewPagesIntoLink
474  && $this->‪isTableAllowedOnPage('pages', $this->pageinfo)
475  && $this->‪getBackendUserAuthentication()->check('tables_modify', 'pages')
476  && $this->‪getBackendUserAuthentication()->workspaceCanCreateNewRecord('pages')
477  ) {
478  // Create link to new page inside:
479  $recordIcon = $this->moduleTemplate->getIconFactory()->getIconForRecord($table, [], ‪Icon::SIZE_SMALL)->render();
480  $newPageLinks[] = $this->‪renderLink(
481  $recordIcon . htmlspecialchars($lang->sL($v['ctrl']['title'])) . ' (' . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:db_new.php.inside')) . ')',
482  $table,
483  $this->id
484  );
485  }
486  // New pages AFTER this pages
487  if ($displayNewPagesAfterLink
488  && $this->‪isTableAllowedOnPage('pages', $this->pidInfo)
489  && $this->‪getBackendUserAuthentication()->check('tables_modify', 'pages')
490  && $this->‪getBackendUserAuthentication()->workspaceCanCreateNewRecord('pages')
491  ) {
492  $newPageLinks[] = $this->‪renderLink(
493  $pageIcon . htmlspecialchars($lang->sL($v['ctrl']['title'])) . ' (' . htmlspecialchars($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:db_new.php.after')) . ')',
494  'pages',
495  -$this->id
496  );
497  }
498  // New pages at selection position
499  if ($this->newPagesSelectPosition && $this->‪isRecordCreationAllowedForTable('pages')) {
500  // Link to page-wizard:
501  $newPageLinks[] = '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(['pagesOnly' => 1])) . '">' . $pageIcon . htmlspecialchars($lang->getLL('pageSelectPosition')) . '</a>';
502  }
503  // Assemble all new page links
504  $numPageLinks = count($newPageLinks);
505  for ($i = 0; $i < $numPageLinks; $i++) {
506  $rowContent .= '<li>' . $newPageLinks[$i] . '</li>';
507  }
508  if ($this->‪isRecordCreationAllowedForTable('pages')) {
509  $rowContent = '<ul class="list-tree"><li>' . $newPageIcon . '<strong>' .
510  $lang->getLL('createNewPage') . '</strong><ul>' . $rowContent . '</ul></li>';
511  } else {
512  $rowContent = '<ul class="list-tree"><li><ul>' . $rowContent . '</li></ul>';
513  }
515  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
516  // Compile table row
517  $startRows = [$rowContent];
518  $iconFile = [];
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'])) {
524  $groupName = '';
525  foreach (‪$GLOBALS['TCA'] as $table => $v) {
527  $rootLevelConfiguration = isset($v['ctrl']['rootLevel']) ? (int)$v['ctrl']['rootLevel'] : 0;
528  if ($table !== 'pages'
529  && $this->‪isRecordCreationAllowedForTable($table)
530  && $this->‪isTableAllowedOnPage($table, $this->pageinfo)
531  && $this->‪getBackendUserAuthentication()->‪check('tables_modify', $table)
532  && ($rootLevelConfiguration === -1 || ($this->id xor $rootLevelConfiguration))
534  ) {
535  $newRecordIcon = $this->moduleTemplate->getIconFactory()->getIconForRecord($table, [], ‪Icon::SIZE_SMALL)->render();
536  $rowContent = '';
537  $thisTitle = '';
538  // Create new link for record:
539  $newLink = $this->‪renderLink(
540  $newRecordIcon . htmlspecialchars($lang->sL($v['ctrl']['title'])),
541  $table,
542  $this->id
543  );
544  // If the table is 'tt_content', add link to wizard
545  if ($table === 'tt_content') {
546  $groupName = $lang->getLL('createNewContent');
547  $rowContent = $newContentIcon
548  . '<strong>' . $lang->getLL('createNewContent') . '</strong>'
549  . '<ul>';
550  // If mod.newContentElementWizard.override is set, use that extension's wizard instead:
551  $moduleName = ‪BackendUtility::getPagesTSconfig($this->id)['mod.']['newContentElementWizard.']['override']
552  ?? 'new_content_element_wizard';
554  $normalizedParams = $request->getAttribute('normalizedParams');
555  $url = (string)$uriBuilder->buildUriFromRoute($moduleName, ['id' => $this->id, 'returnUrl' => $normalizedParams->getRequestUri()]);
556  $title = htmlspecialchars($this->‪getLanguageService()->getLL('newContentElement'));
557  $rowContent .= '<li>' . $newLink . ' ' . ‪BackendUtility::wrapInHelp($table, '') . '</li>'
558  . '<li>'
559  . '<a href="' . htmlspecialchars($url) . '" title="' . $title . '" data-title="' . $title . '" class="t3js-toggle-new-content-element-wizard disabled">'
560  . $newContentIcon . htmlspecialchars($lang->getLL('clickForWizard'))
561  . '</a>'
562  . '</li>'
563  . '</ul>';
564  } else {
565  // Get the title
566  if ($v['ctrl']['readOnly'] || $v['ctrl']['hideTable'] || $v['ctrl']['is_static']) {
567  continue;
568  }
569  if ($v['ctrl']['adminOnly'] && !$isAdmin) {
570  continue;
571  }
572  $nameParts = explode('_', $table);
573  $thisTitle = '';
574  $_EXTKEY = '';
575  if ($nameParts[0] === 'tx' || $nameParts[0] === 'tt') {
576  // Try to extract extension name
577  $title = (string)($v['ctrl']['title'] ?? '');
578  if (strpos($title, 'LLL:EXT:') === 0) {
579  $_EXTKEY = substr($title, 8);
580  $_EXTKEY = substr($_EXTKEY, 0, (int)strpos($_EXTKEY, '/'));
581  if ($_EXTKEY !== '') {
582  // First try to get localisation of extension title
583  $temp = explode(':', substr($title, 9 + strlen($_EXTKEY)));
584  $langFile = $temp[0];
585  $thisTitle = $lang->sL('LLL:EXT:' . $_EXTKEY . '/' . $langFile . ':extension.title');
586  // If no localisation available, read title from ext_emconf.php
587  $extPath = ‪ExtensionManagementUtility::extPath($_EXTKEY);
588  $extEmConfFile = $extPath . 'ext_emconf.php';
589  if (!$thisTitle && is_file($extEmConfFile)) {
590  ‪$EM_CONF = [];
591  include $extEmConfFile;
592  $thisTitle = ‪$EM_CONF[$_EXTKEY]['title'];
593  }
594  $iconFile[$_EXTKEY] = '<img src="' . ‪PathUtility::getAbsoluteWebPath(‪ExtensionManagementUtility::getExtensionIcon($extPath, true)) . '" width="16" height="16" alt="' . $thisTitle . '" />';
595  }
596  }
597  if (empty($thisTitle)) {
598  $_EXTKEY = $nameParts[1];
599  $thisTitle = $nameParts[1];
600  $iconFile[$_EXTKEY] = '';
601  }
602  } else {
603  $_EXTKEY = 'system';
604  $thisTitle = $lang->getLL('system_records');
605  $iconFile['system'] = $this->moduleTemplate->getIconFactory()->getIcon('apps-pagetree-root', ‪Icon::SIZE_SMALL)->render();
606  }
607 
608  if ($groupName === '' || $groupName !== $_EXTKEY) {
609  $groupName = empty($v['ctrl']['groupName']) ? $_EXTKEY : $v['ctrl']['groupName'];
610  }
611  $rowContent .= $newLink;
612  }
613  // Compile table row:
614  if ($table === 'tt_content') {
615  $startRows[] = '<li>' . $rowContent . '</li>';
616  } else {
617  $this->tRows[$groupName]['title'] = $thisTitle;
618  $this->tRows[$groupName]['html'][] = $rowContent;
619  $this->tRows[$groupName]['table'][] = $table;
620  }
621  }
622  }
623  }
624  }
625  // User sort
626  if (isset($pageTS['mod.']['wizards.']['newRecord.']['order'])) {
627  $this->newRecordSortList = ‪GeneralUtility::trimExplode(',', $pageTS['mod.']['wizards.']['newRecord.']['order'], true);
628  }
629  uksort($this->tRows, [$this, 'sortTableRows']);
630  // Compile table row:
631  $finalRows = [];
632  $finalRows[] = implode('', $startRows);
633  foreach ($this->tRows as $key => $value) {
634  $row = '<li>' . $iconFile[$key] . ' <strong>' . $value['title'] . '</strong><ul>';
635  foreach ($value['html'] as $recordKey => $record) {
636  $row .= '<li>' . $record . ' ' . ‪BackendUtility::wrapInHelp($value['table'][$recordKey], '') . '</li>';
637  }
638  $row .= '</ul></li>';
639  $finalRows[] = $row;
640  }
641 
642  $finalRows[] = '</ul>';
643  // Make table:
644  $this->code .= implode('', $finalRows);
645  }
646 
654  protected function ‪sortTableRows(string $a, string $b): int
655  {
656  if (!empty($this->newRecordSortList)) {
657  if (in_array($a, $this->newRecordSortList) && in_array($b, $this->newRecordSortList)) {
658  // Both are in the list, return relative to position in array
659  $sub = array_search($a, $this->newRecordSortList) - array_search($b, $this->newRecordSortList);
660  $ret = ($sub < 0 ? -1 : $sub == 0) ? 0 : 1;
661  } elseif (in_array($a, $this->newRecordSortList)) {
662  // First element is in array, put to top
663  $ret = -1;
664  } elseif (in_array($b, $this->newRecordSortList)) {
665  // Second element is in array, put first to bottom
666  $ret = 1;
667  } else {
668  // No element is in array, return alphabetic order
669  $ret = strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
670  }
671  return $ret;
672  }
673  // Return alphabetic order
674  return strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
675  }
676 
686  protected function ‪renderLink(string $linkText, string $table, int $pid, bool $addContentTable = false): string
687  {
688  $urlParameters = [
689  'edit' => [
690  $table => [
691  $pid => 'new'
692  ]
693  ],
694  'returnUrl' => ‪$this->returnUrl
695  ];
696 
697  if ($table === 'pages' && $addContentTable) {
698  $urlParameters['tt_content']['prev'] = 'new';
699  $urlParameters['returnNewPageId'] = 1;
700  }
701 
702  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
703  $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
704 
705  return '<a href="' . htmlspecialchars($url) . '">' . $linkText . '</a>';
706  }
707 
715  protected function ‪isTableAllowedOnPage(string $table, array $page): bool
716  {
717  if (empty($page)) {
718  return $this->‪getBackendUserAuthentication()->‪isAdmin();
719  }
720  // be_users and be_groups may not be created anywhere but in the root.
721  if ($table === 'be_users' || $table === 'be_groups') {
722  return false;
723  }
724  // Checking doktype:
725  $doktype = (int)$page['doktype'];
726  if (!($allowedTableList = ‪$GLOBALS['PAGES_TYPES'][$doktype]['allowedTables'])) {
727  $allowedTableList = ‪$GLOBALS['PAGES_TYPES']['default']['allowedTables'];
728  }
729  // If all tables or the table is listed as an allowed type, return TRUE
730  if (strpos($allowedTableList, '*') !== false || GeneralUtility::inList($allowedTableList, $table)) {
731  return true;
732  }
733 
734  return false;
735  }
736 
753  protected function ‪isRecordCreationAllowedForTable(string $table, array ‪$allowedNewTables = [], array ‪$deniedNewTables = []): bool
754  {
755  if (!$this->‪getBackendUserAuthentication()->check('tables_modify', $table)) {
756  return false;
757  }
758 
761  // No deny/allow tables are set:
762  if (empty(‪$allowedNewTables) && empty(‪$deniedNewTables)) {
763  return true;
764  }
765 
766  return !in_array($table, ‪$deniedNewTables) && (empty(‪$allowedNewTables) || in_array($table, ‪$allowedNewTables));
767  }
768 
772  protected function ‪getLanguageService(): LanguageService
773  {
774  return ‪$GLOBALS['LANG'];
775  }
776 
780  protected function ‪getBackendUserAuthentication(): BackendUserAuthentication
781  {
782  return ‪$GLOBALS['BE_USER'];
783  }
784 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Backend\Controller\NewRecordController\$id
‪int $id
Definition: NewRecordController.php:110
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:24
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪array includeLLFile($fileRef, $setGlobal=null, $mergeLocalOntoDefault=null)
Definition: LanguageService.php:297
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_LEFT
‪const BUTTON_POSITION_LEFT
Definition: ButtonBar.php:36
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:32
‪TYPO3\CMS\Backend\Controller\NewRecordController\renderNewRecordControls
‪renderNewRecordControls(ServerRequestInterface $request)
Definition: NewRecordController.php:424
‪TYPO3\CMS\Backend\Controller\NewRecordController\$deniedNewTables_pid
‪array $deniedNewTables_pid
Definition: NewRecordController.php:99
‪TYPO3\CMS\Backend\Controller\NewRecordController\$web_list_modTSconfig_pid
‪array $web_list_modTSconfig_pid
Definition: NewRecordController.php:91
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Backend\Controller\NewRecordController\getLanguageService
‪LanguageService getLanguageService()
Definition: NewRecordController.php:751
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isAdmin
‪bool isAdmin()
Definition: BackendUserAuthentication.php:292
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\check
‪bool check($type, $value)
Definition: BackendUserAuthentication.php:624
‪TYPO3\CMS\Backend\Controller\NewRecordController\$newContentInto
‪int $newContentInto
Definition: NewRecordController.php:65
‪TYPO3\CMS\Backend\Utility\BackendUtility\cshItem
‪static string cshItem($table, $field, $_='', $wrap='')
Definition: BackendUtility.php:2306
‪TYPO3\CMS\Backend\Controller\NewRecordController\renderPositionTree
‪ResponseInterface null renderPositionTree()
Definition: NewRecordController.php:376
‪TYPO3\CMS\Backend\Controller\NewRecordController\$code
‪string $code
Definition: NewRecordController.php:103
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\workspaceCanCreateNewRecord
‪bool workspaceCanCreateNewRecord(string $table)
Definition: BackendUserAuthentication.php:1046
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:194
‪TYPO3\CMS\Backend\Controller\NewRecordController\isTableAllowedOnPage
‪bool isTableAllowedOnPage(string $table, array $page)
Definition: NewRecordController.php:694
‪TYPO3\CMS\Backend\Controller\NewRecordController\getButtons
‪getButtons()
Definition: NewRecordController.php:302
‪TYPO3\CMS\Backend\Utility\BackendUtility\BEgetRootLine
‪static array BEgetRootLine($uid, $clause='', $workspaceOL=false, array $additionalFields=[])
Definition: BackendUtility.php:343
‪TYPO3\CMS\Backend\Controller\NewRecordController\$returnUrl
‪string $returnUrl
Definition: NewRecordController.php:114
‪TYPO3\CMS\Backend\Utility\BackendUtility\wrapInHelp
‪static string wrapInHelp($table, $field, $text='', array $overloadHelpText=[])
Definition: BackendUtility.php:2260
‪TYPO3\CMS\Backend\Controller\NewRecordController\renderLink
‪string renderLink(string $linkText, string $table, int $pid, bool $addContentTable=false)
Definition: NewRecordController.php:665
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:43
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:24
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Backend\Controller\NewRecordController
Definition: NewRecordController.php:46
‪TYPO3\CMS\Backend\Controller\NewRecordController\$deniedNewTables
‪array $deniedNewTables
Definition: NewRecordController.php:87
‪TYPO3\CMS\Backend\Controller\NewRecordController\$pageinfo
‪array $pageinfo
Definition: NewRecordController.php:49
‪TYPO3\CMS\Backend\Controller\NewRecordController\$web_list_modTSconfig
‪array $web_list_modTSconfig
Definition: NewRecordController.php:79
‪TYPO3\CMS\Backend\Controller\NewRecordController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: NewRecordController.php:140
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap
Definition: PagePositionMap.php:39
‪TYPO3\CMS\Backend\Tree\View\NewRecordPageTreeView
Definition: NewRecordPageTreeView.php:25
‪TYPO3\CMS\Backend\Controller\NewRecordController\$newPagesSelectPosition
‪bool $newPagesSelectPosition
Definition: NewRecordController.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getPagesTSconfig
‪static array getPagesTSconfig($id)
Definition: BackendUtility.php:698
‪TYPO3\CMS\Backend\Controller\NewRecordController\$newPagesAfter
‪int $newPagesAfter
Definition: NewRecordController.php:69
‪TYPO3\CMS\Core\Domain\Repository\PageRepository\DOKTYPE_SPACER
‪const DOKTYPE_SPACER
Definition: PageRepository.php:108
‪TYPO3\CMS\Backend\Controller\NewRecordController\sortTableRows
‪int sortTableRows(string $a, string $b)
Definition: NewRecordController.php:633
‪TYPO3\CMS\Backend\Controller\NewRecordController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: NewRecordController.php:158
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:33
‪TYPO3\CMS\Core\Domain\Repository\PageRepository\DOKTYPE_SYSFOLDER
‪const DOKTYPE_SYSFOLDER
Definition: PageRepository.php:109
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:95
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:28
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Backend\Controller\NewRecordController\getBackendUserAuthentication
‪BackendUserAuthentication getBackendUserAuthentication()
Definition: NewRecordController.php:759
‪TYPO3\CMS\Backend\Utility\BackendUtility\readPageAccess
‪static array false readPageAccess($id, $perms_clause)
Definition: BackendUtility.php:597
‪TYPO3\CMS\Backend\Controller\NewRecordController\init
‪init(ServerRequestInterface $request)
Definition: NewRecordController.php:175
‪TYPO3\CMS\Backend\Controller\NewRecordController\$newPagesInto
‪int $newPagesInto
Definition: NewRecordController.php:61
‪TYPO3\CMS\Backend\Utility\BackendUtility\viewOnClick
‪static string viewOnClick( $pageUid, $backPath='', $rootLine=null, $anchorSection='', $alternativeUrl='', $additionalGetVars='', $switchFocus=true)
Definition: BackendUtility.php:2359
‪TYPO3\CMS\Backend\Controller\NewRecordController\__construct
‪__construct()
Definition: NewRecordController.php:145
‪TYPO3\CMS\Backend\Controller\NewRecordController\renderContent
‪ResponseInterface null renderContent(ServerRequestInterface $request)
Definition: NewRecordController.php:244
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Backend\Controller\NewRecordController\$newRecordSortList
‪array $newRecordSortList
Definition: NewRecordController.php:57
‪TYPO3\CMS\Core\Utility\GeneralUtility\intExplode
‪static int[] intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:988
‪TYPO3\CMS\Backend\Controller\NewRecordController\$pidInfo
‪array $pidInfo
Definition: NewRecordController.php:53
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\extPath
‪static string extPath($key, $script='')
Definition: ExtensionManagementUtility.php:127
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪$EM_CONF
‪$EM_CONF[$_EXTKEY]
Definition: ext_emconf.php:3
‪TYPO3\CMS\Core\Domain\Repository\PageRepository
Definition: PageRepository.php:52
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\getExtensionIcon
‪static string getExtensionIcon($extensionPath, $returnFullPath=false)
Definition: ExtensionManagementUtility.php:1518
‪TYPO3\CMS\Backend\Controller\NewRecordController\isRecordCreationAllowedForTable
‪bool isRecordCreationAllowedForTable(string $table, array $allowedNewTables=[], array $deniedNewTables=[])
Definition: NewRecordController.php:732
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Controller\NewRecordController\$content
‪string $content
Definition: NewRecordController.php:130
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:43
‪TYPO3\CMS\Backend\Controller\NewRecordController\$pagesOnly
‪int $pagesOnly
Definition: NewRecordController.php:120
‪TYPO3\CMS\Backend\Controller\NewRecordController\$tRows
‪array $tRows
Definition: NewRecordController.php:134
‪TYPO3\CMS\Backend\Controller
Definition: AbstractFormEngineAjaxController.php:18
‪TYPO3\CMS\Core\Domain\Repository\PageRepository\DOKTYPE_RECYCLER
‪const DOKTYPE_RECYCLER
Definition: PageRepository.php:110
‪TYPO3\CMS\Backend\Controller\NewRecordController\$allowedNewTables_pid
‪array $allowedNewTables_pid
Definition: NewRecordController.php:95
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26
‪TYPO3\CMS\Backend\Controller\NewRecordController\$perms_clause
‪string $perms_clause
Definition: NewRecordController.php:124
‪TYPO3\CMS\Backend\Controller\NewRecordController\$allowedNewTables
‪array $allowedNewTables
Definition: NewRecordController.php:83