| Total Complexity | 105 |
| Total Lines | 732 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like NewRecordController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use NewRecordController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 49 | class NewRecordController |
||
| 50 | { |
||
| 51 | /** |
||
| 52 | * @var array |
||
| 53 | */ |
||
| 54 | protected $pageinfo = []; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var array |
||
| 58 | */ |
||
| 59 | protected $pidInfo = []; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var array |
||
| 63 | */ |
||
| 64 | protected $newRecordSortList; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var int |
||
| 68 | */ |
||
| 69 | protected $newPagesInto; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var int |
||
| 73 | */ |
||
| 74 | protected $newContentInto; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var int |
||
| 78 | */ |
||
| 79 | protected $newPagesAfter; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Determines, whether "Select Position" for new page should be shown |
||
| 83 | * |
||
| 84 | * @var bool |
||
| 85 | */ |
||
| 86 | protected $newPagesSelectPosition = true; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @var array |
||
| 90 | */ |
||
| 91 | protected $web_list_modTSconfig; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @var array |
||
| 95 | */ |
||
| 96 | protected $allowedNewTables; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @var array |
||
| 100 | */ |
||
| 101 | protected $deniedNewTables; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @var array |
||
| 105 | */ |
||
| 106 | protected $web_list_modTSconfig_pid; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @var array |
||
| 110 | */ |
||
| 111 | protected $allowedNewTables_pid; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @var array |
||
| 115 | */ |
||
| 116 | protected $deniedNewTables_pid; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @var string |
||
| 120 | */ |
||
| 121 | protected $code; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @var int |
||
| 125 | * |
||
| 126 | * @see \TYPO3\CMS\Backend\Tree\View\NewRecordPageTreeView::expandNext() |
||
| 127 | * @internal |
||
| 128 | */ |
||
| 129 | public $id; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @var string |
||
| 133 | */ |
||
| 134 | protected $returnUrl; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * pagesOnly flag. |
||
| 138 | * |
||
| 139 | * @var int |
||
| 140 | */ |
||
| 141 | protected $pagesOnly; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @var string |
||
| 145 | */ |
||
| 146 | protected $perms_clause; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Accumulated HTML output |
||
| 150 | * |
||
| 151 | * @var string |
||
| 152 | */ |
||
| 153 | protected $content; |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @var array |
||
| 157 | */ |
||
| 158 | protected $tRows; |
||
| 159 | |||
| 160 | /** |
||
| 161 | * ModuleTemplate object |
||
| 162 | * |
||
| 163 | * @var ModuleTemplate |
||
| 164 | */ |
||
| 165 | protected $moduleTemplate; |
||
| 166 | |||
| 167 | protected PageRenderer $pageRenderer; |
||
| 168 | protected IconFactory $iconFactory; |
||
| 169 | protected UriBuilder $uriBuilder; |
||
| 170 | protected ModuleTemplateFactory $moduleTemplateFactory; |
||
| 171 | |||
| 172 | public function __construct( |
||
| 173 | IconFactory $iconFactory, |
||
| 174 | PageRenderer $pageRenderer, |
||
| 175 | UriBuilder $uriBuilder, |
||
| 176 | ModuleTemplateFactory $moduleTemplateFactory |
||
| 177 | ) { |
||
| 178 | $this->iconFactory = $iconFactory; |
||
| 179 | $this->pageRenderer = $pageRenderer; |
||
| 180 | $this->uriBuilder = $uriBuilder; |
||
| 181 | $this->moduleTemplateFactory = $moduleTemplateFactory; |
||
| 182 | } |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Injects the request object for the current request or subrequest |
||
| 186 | * As this controller goes only through the main() method, it is rather simple for now |
||
| 187 | * |
||
| 188 | * @param ServerRequestInterface $request the current request |
||
| 189 | * @return ResponseInterface the response with the content |
||
| 190 | */ |
||
| 191 | public function mainAction(ServerRequestInterface $request): ResponseInterface |
||
| 192 | { |
||
| 193 | $this->init($request); |
||
| 194 | $response = $this->renderContent($request); |
||
| 195 | |||
| 196 | if (empty($response)) { |
||
| 197 | $response = new HtmlResponse($this->moduleTemplate->renderContent()); |
||
| 198 | } |
||
| 199 | |||
| 200 | return $response; |
||
| 201 | } |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Constructor function for the class |
||
| 205 | * |
||
| 206 | * @param ServerRequestInterface $request |
||
| 207 | */ |
||
| 208 | protected function init(ServerRequestInterface $request): void |
||
| 209 | { |
||
| 210 | $this->moduleTemplate = $this->moduleTemplateFactory->create($request); |
||
| 211 | $this->getLanguageService()->includeLLFile('EXT:core/Resources/Private/Language/locallang_misc.xlf'); |
||
| 212 | $beUser = $this->getBackendUserAuthentication(); |
||
| 213 | // Page-selection permission clause (reading) |
||
| 214 | $this->perms_clause = $beUser->getPagePermsClause(Permission::PAGE_SHOW); |
||
| 215 | // This will hide records from display - it has nothing to do with user rights!! |
||
| 216 | $pidList = $beUser->getTSConfig()['options.']['hideRecords.']['pages'] ?? ''; |
||
| 217 | if (!empty($pidList)) { |
||
| 218 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 219 | ->getQueryBuilderForTable('pages'); |
||
| 220 | $this->perms_clause .= ' AND ' . $queryBuilder->expr()->notIn( |
||
| 221 | 'pages.uid', |
||
| 222 | GeneralUtility::intExplode(',', $pidList) |
||
| 223 | ); |
||
| 224 | } |
||
| 225 | // Setting GPvars: |
||
| 226 | $parsedBody = $request->getParsedBody(); |
||
| 227 | $queryParams = $request->getQueryParams(); |
||
| 228 | // The page id to operate from |
||
| 229 | $this->id = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0); |
||
| 230 | $this->returnUrl = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? ''); |
||
| 231 | $this->pagesOnly = $parsedBody['pagesOnly'] ?? $queryParams['pagesOnly'] ?? null; |
||
| 232 | // Setting up the context sensitive menu: |
||
| 233 | $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu'); |
||
| 234 | $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip'); |
||
| 235 | $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/PageActions'); |
||
| 236 | // Creating content |
||
| 237 | $this->content = ''; |
||
| 238 | $this->content .= '<h1>' |
||
| 239 | . $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:db_new.php.pagetitle') |
||
| 240 | . '</h1>'; |
||
| 241 | // Id a positive id is supplied, ask for the page record with permission information contained: |
||
| 242 | if ($this->id > 0) { |
||
| 243 | $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause) ?: []; |
||
| 244 | } |
||
| 245 | // If a page-record was returned, the user had read-access to the page. |
||
| 246 | if ($this->pageinfo['uid'] ?? false) { |
||
| 247 | // Get record of parent page |
||
| 248 | $this->pidInfo = BackendUtility::getRecord('pages', ($this->pageinfo['pid'] ?? 0)) ?? []; |
||
| 249 | // Checking the permissions for the user with regard to the parent page: Can he create new pages, new |
||
| 250 | // content record, new page after? |
||
| 251 | if ($beUser->doesUserHaveAccess($this->pageinfo, 8)) { |
||
| 252 | $this->newPagesInto = 1; |
||
| 253 | } |
||
| 254 | if ($beUser->doesUserHaveAccess($this->pageinfo, 16)) { |
||
| 255 | $this->newContentInto = 1; |
||
| 256 | } |
||
| 257 | if (($beUser->isAdmin() || !empty($this->pidInfo)) && $beUser->doesUserHaveAccess($this->pidInfo, 8)) { |
||
| 258 | $this->newPagesAfter = 1; |
||
| 259 | } |
||
| 260 | } elseif ($beUser->isAdmin()) { |
||
| 261 | // Admins can do it all |
||
| 262 | $this->newPagesInto = 1; |
||
| 263 | $this->newContentInto = 1; |
||
| 264 | $this->newPagesAfter = 0; |
||
| 265 | } else { |
||
| 266 | // People with no permission can do nothing |
||
| 267 | $this->newPagesInto = 0; |
||
| 268 | $this->newContentInto = 0; |
||
| 269 | $this->newPagesAfter = 0; |
||
| 270 | } |
||
| 271 | } |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Main processing, creating the list of new record tables to select from |
||
| 275 | * |
||
| 276 | * @param ServerRequestInterface $request |
||
| 277 | * @return ResponseInterface|null |
||
| 278 | */ |
||
| 279 | protected function renderContent(ServerRequestInterface $request): ?ResponseInterface |
||
| 280 | { |
||
| 281 | // If there was a page - or if the user is admin (admins has access to the root) we proceed: |
||
| 282 | if (!empty($this->pageinfo['uid']) || $this->getBackendUserAuthentication()->isAdmin()) { |
||
| 283 | $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo); |
||
| 284 | // Acquiring TSconfig for this module/current page: |
||
| 285 | $this->web_list_modTSconfig = BackendUtility::getPagesTSconfig($this->pageinfo['uid'] ?? 0)['mod.']['web_list.'] ?? []; |
||
| 286 | $this->allowedNewTables = GeneralUtility::trimExplode(',', $this->web_list_modTSconfig['allowedNewTables'] ?? '', true); |
||
| 287 | $this->deniedNewTables = GeneralUtility::trimExplode(',', $this->web_list_modTSconfig['deniedNewTables'] ?? '', true); |
||
| 288 | // Acquiring TSconfig for this module/parent page: |
||
| 289 | $this->web_list_modTSconfig_pid = BackendUtility::getPagesTSconfig($this->pageinfo['pid'] ?? 0)['mod.']['web_list.'] ?? []; |
||
| 290 | $this->allowedNewTables_pid = GeneralUtility::trimExplode(',', $this->web_list_modTSconfig_pid['allowedNewTables'] ?? '', true); |
||
| 291 | $this->deniedNewTables_pid = GeneralUtility::trimExplode(',', $this->web_list_modTSconfig_pid['deniedNewTables'] ?? '', true); |
||
| 292 | // More init: |
||
| 293 | if (!$this->isRecordCreationAllowedForTable('pages')) { |
||
| 294 | $this->newPagesInto = 0; |
||
| 295 | } |
||
| 296 | if (!$this->isRecordCreationAllowedForTable('pages', $this->allowedNewTables_pid, $this->deniedNewTables_pid)) { |
||
| 297 | $this->newPagesAfter = 0; |
||
| 298 | } |
||
| 299 | // Set header-HTML and return_url |
||
| 300 | if ($this->pageinfo['uid'] ?? false) { |
||
| 301 | $title = strip_tags($this->pageinfo[$GLOBALS['TCA']['pages']['ctrl']['label']]); |
||
| 302 | } else { |
||
| 303 | $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']; |
||
| 304 | } |
||
| 305 | $this->moduleTemplate->setTitle($title); |
||
| 306 | // GENERATE the HTML-output depending on mode (pagesOnly is the page wizard) |
||
| 307 | // Regular new element: |
||
| 308 | if (!$this->pagesOnly) { |
||
| 309 | $this->renderNewRecordControls($request); |
||
| 310 | } elseif ($this->isRecordCreationAllowedForTable('pages')) { |
||
| 311 | // Pages only wizard |
||
| 312 | $response = $this->renderPositionTree(); |
||
| 313 | |||
| 314 | if (!empty($response)) { |
||
| 315 | return $response; |
||
| 316 | } |
||
| 317 | } |
||
| 318 | // Add all the content to an output section |
||
| 319 | $this->content .= '<div>' . $this->code . '</div>'; |
||
| 320 | // Setting up the buttons and markers for docheader |
||
| 321 | $this->getButtons(); |
||
| 322 | // Build the <body> for the module |
||
| 323 | $this->moduleTemplate->setContent($this->content); |
||
| 324 | } |
||
| 325 | |||
| 326 | return null; |
||
| 327 | } |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Create the panel of buttons for submitting the form or otherwise perform operations. |
||
| 331 | */ |
||
| 332 | protected function getButtons(): void |
||
| 333 | { |
||
| 334 | $buttons = []; |
||
| 335 | $lang = $this->getLanguageService(); |
||
| 336 | $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar(); |
||
| 337 | // Regular new element: |
||
| 338 | if (!$this->pagesOnly) { |
||
| 339 | // New page |
||
| 340 | if ($this->isRecordCreationAllowedForTable('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->iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL)); |
||
| 345 | $buttonBar->addButton($newPageButton, ButtonBar::BUTTON_POSITION_LEFT, 20); |
||
| 346 | } |
||
| 347 | // CSH |
||
| 348 | $cshButton = $buttonBar->makeHelpButton()->setModuleName('xMOD_csh_corebe')->setFieldName('new_regular'); |
||
| 349 | $buttonBar->addButton($cshButton); |
||
| 350 | } elseif ($this->isRecordCreationAllowedForTable('pages')) { |
||
| 351 | // Pages only wizard |
||
| 352 | // CSH |
||
| 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); |
||
| 356 | } |
||
| 357 | // Back |
||
| 358 | if ($this->returnUrl) { |
||
| 359 | $returnButton = $buttonBar->makeLinkButton() |
||
| 360 | ->setHref($this->returnUrl) |
||
| 361 | ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack')) |
||
| 362 | ->setIcon($this->iconFactory->getIcon('actions-view-go-back', Icon::SIZE_SMALL)); |
||
| 363 | $buttonBar->addButton($returnButton, ButtonBar::BUTTON_POSITION_LEFT, 10); |
||
| 364 | } |
||
| 365 | |||
| 366 | if ($this->pageinfo['uid'] ?? false) { |
||
| 367 | // View |
||
| 368 | $pagesTSconfig = BackendUtility::getPagesTSconfig($this->pageinfo['uid']); |
||
| 369 | if (isset($pagesTSconfig['TCEMAIN.']['preview.']['disableButtonForDokType'])) { |
||
| 370 | $excludeDokTypes = GeneralUtility::intExplode( |
||
| 371 | ',', |
||
| 372 | $pagesTSconfig['TCEMAIN.']['preview.']['disableButtonForDokType'], |
||
| 373 | true |
||
| 374 | ); |
||
| 375 | } else { |
||
| 376 | // exclude sysfolders and recycler by default |
||
| 377 | $excludeDokTypes = [ |
||
| 378 | PageRepository::DOKTYPE_RECYCLER, |
||
| 379 | PageRepository::DOKTYPE_SYSFOLDER, |
||
| 380 | PageRepository::DOKTYPE_SPACER |
||
| 381 | ]; |
||
| 382 | } |
||
| 383 | if (!in_array((int)$this->pageinfo['doktype'], $excludeDokTypes, true)) { |
||
| 384 | $previewDataAttributes = PreviewUriBuilder::create((int)$this->pageinfo['uid']) |
||
| 385 | ->withRootLine(BackendUtility::BEgetRootLine($this->pageinfo['uid'])) |
||
| 386 | ->buildDispatcherDataAttributes(); |
||
| 387 | $viewButton = $buttonBar->makeLinkButton() |
||
| 388 | ->setHref('#') |
||
| 389 | ->setDataAttributes($previewDataAttributes ?? []) |
||
| 390 | ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage')) |
||
| 391 | ->setIcon($this->iconFactory->getIcon( |
||
| 392 | 'actions-view-page', |
||
| 393 | Icon::SIZE_SMALL |
||
| 394 | )); |
||
| 395 | $buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 30); |
||
| 396 | } |
||
| 397 | } |
||
| 398 | } |
||
| 399 | |||
| 400 | /** |
||
| 401 | * Renders the position map for pages wizard |
||
| 402 | * |
||
| 403 | * @return ResponseInterface|null |
||
| 404 | */ |
||
| 405 | protected function renderPositionTree(): ?ResponseInterface |
||
| 406 | { |
||
| 407 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 408 | ->getQueryBuilderForTable('pages'); |
||
| 409 | $queryBuilder->getRestrictions() |
||
| 410 | ->removeAll() |
||
| 411 | ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); |
||
| 412 | $numberOfPages = $queryBuilder |
||
| 413 | ->count('*') |
||
| 414 | ->from('pages') |
||
| 415 | ->execute() |
||
| 416 | ->fetchColumn(0); |
||
| 417 | |||
| 418 | if ($numberOfPages > 0) { |
||
| 419 | $this->code .= '<h3>' . htmlspecialchars($this->getLanguageService()->getLL('selectPosition')) . ':</h3>'; |
||
| 420 | $positionMap = GeneralUtility::makeInstance(PagePositionMap::class, NewRecordPageTreeView::class); |
||
| 421 | $this->code .= $positionMap->positionTree( |
||
| 422 | $this->id, |
||
| 423 | $this->pageinfo, |
||
| 424 | $this->perms_clause, |
||
| 425 | $this->returnUrl |
||
| 426 | ); |
||
| 427 | } else { |
||
| 428 | // No pages yet, no need to prompt for position, redirect to page creation. |
||
| 429 | $urlParameters = [ |
||
| 430 | 'edit' => [ |
||
| 431 | 'pages' => [ |
||
| 432 | 0 => 'new' |
||
| 433 | ] |
||
| 434 | ], |
||
| 435 | 'returnNewPageId' => 1, |
||
| 436 | 'returnUrl' => (string)$this->uriBuilder->buildUriFromRoute('db_new', ['id' => $this->id, 'pagesOnly' => '1']) |
||
| 437 | ]; |
||
| 438 | $url = (string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters); |
||
| 439 | @ob_end_clean(); |
||
| 440 | |||
| 441 | return new RedirectResponse($url); |
||
| 442 | } |
||
| 443 | |||
| 444 | return null; |
||
| 445 | } |
||
| 446 | |||
| 447 | /** |
||
| 448 | * Render controls for creating a regular new element (pages or records) |
||
| 449 | * |
||
| 450 | * @param ServerRequestInterface $request |
||
| 451 | */ |
||
| 452 | protected function renderNewRecordControls(ServerRequestInterface $request): void |
||
| 651 | } |
||
| 652 | |||
| 653 | /** |
||
| 654 | * User array sort function used by renderNewRecordControls |
||
| 655 | * |
||
| 656 | * @param string $a First array element for compare |
||
| 657 | * @param string $b First array element for compare |
||
| 658 | * @return int -1 for lower, 0 for equal, 1 for greater |
||
| 659 | */ |
||
| 660 | protected function sortTableRows(string $a, string $b): int |
||
| 681 | } |
||
| 682 | |||
| 683 | /** |
||
| 684 | * Links the string $code to a create-new form for a record in $table created on page $pid |
||
| 685 | * |
||
| 686 | * @param string $linkText Link text |
||
| 687 | * @param string $table Table name (in which to create new record) |
||
| 688 | * @param int $pid PID value for the "&edit['.$table.']['.$pid.']=new" command (positive/negative) |
||
| 689 | * @param bool $addContentTable If $addContentTable is set, then a new tt_content record is created together with pages |
||
| 690 | * @return string The link. |
||
| 691 | */ |
||
| 692 | protected function renderLink(string $linkText, string $table, int $pid, bool $addContentTable = false): string |
||
| 693 | { |
||
| 694 | $urlParameters = [ |
||
| 695 | 'edit' => [ |
||
| 696 | $table => [ |
||
| 697 | $pid => 'new' |
||
| 698 | ] |
||
| 699 | ], |
||
| 700 | 'returnUrl' => $this->returnUrl |
||
| 701 | ]; |
||
| 702 | |||
| 703 | if ($table === 'pages' && $addContentTable) { |
||
| 704 | $urlParameters['tt_content']['prev'] = 'new'; |
||
| 705 | $urlParameters['returnNewPageId'] = 1; |
||
| 706 | } |
||
| 707 | |||
| 708 | return '<a href="' . htmlspecialchars((string)$this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters)) . '">' . $linkText . '</a>'; |
||
| 709 | } |
||
| 710 | |||
| 711 | /** |
||
| 712 | * Returns TRUE if the tablename $checkTable is allowed to be created on the page with record $pid_row |
||
| 713 | * |
||
| 714 | * @param string $table Table name to check |
||
| 715 | * @param array $page Potential parent page |
||
| 716 | * @return bool Returns TRUE if the tablename $table is allowed to be created on the $page |
||
| 717 | */ |
||
| 718 | protected function isTableAllowedOnPage(string $table, array $page): bool |
||
| 719 | { |
||
| 720 | if (empty($page)) { |
||
| 721 | return $this->getBackendUserAuthentication()->isAdmin(); |
||
| 722 | } |
||
| 723 | // be_users and be_groups may not be created anywhere but in the root. |
||
| 724 | if ($table === 'be_users' || $table === 'be_groups') { |
||
| 725 | return false; |
||
| 726 | } |
||
| 727 | // Checking doktype: |
||
| 728 | $doktype = (int)$page['doktype']; |
||
| 729 | $allowedTableList = $GLOBALS['PAGES_TYPES'][$doktype]['allowedTables'] ?? $GLOBALS['PAGES_TYPES']['default']['allowedTables'] ?? ''; |
||
| 730 | // If all tables or the table is listed as an allowed type, return TRUE |
||
| 731 | |||
| 732 | return strpos($allowedTableList, '*') !== false || GeneralUtility::inList($allowedTableList, $table); |
||
| 733 | } |
||
| 734 | |||
| 735 | /** |
||
| 736 | * Returns whether the record link should be shown for a table |
||
| 737 | * |
||
| 738 | * Returns TRUE if: |
||
| 739 | * - $allowedNewTables and $deniedNewTables are empty |
||
| 740 | * - the table is not found in $deniedNewTables and $allowedNewTables is not set or the $table tablename is found in |
||
| 741 | * $allowedNewTables |
||
| 742 | * |
||
| 743 | * If $table tablename is found in $allowedNewTables and $deniedNewTables, |
||
| 744 | * $deniedNewTables has priority over $allowedNewTables. |
||
| 745 | * |
||
| 746 | * @param string $table Table name to test if in allowedTables |
||
| 747 | * @param array $allowedNewTables Array of new tables that are allowed. |
||
| 748 | * @param array $deniedNewTables Array of new tables that are not allowed. |
||
| 749 | * @return bool Returns TRUE if a link for creating new records should be displayed for $table |
||
| 750 | */ |
||
| 751 | protected function isRecordCreationAllowedForTable(string $table, array $allowedNewTables = [], array $deniedNewTables = []): bool |
||
| 752 | { |
||
| 753 | if (!$this->getBackendUserAuthentication()->check('tables_modify', $table)) { |
||
| 754 | return false; |
||
| 755 | } |
||
| 756 | |||
| 757 | $allowedNewTables = $allowedNewTables ?: $this->allowedNewTables; |
||
| 758 | $deniedNewTables = $deniedNewTables ?: $this->deniedNewTables; |
||
| 759 | // No deny/allow tables are set: |
||
| 760 | if (empty($allowedNewTables) && empty($deniedNewTables)) { |
||
| 761 | return true; |
||
| 762 | } |
||
| 763 | |||
| 764 | return !in_array($table, $deniedNewTables) && (empty($allowedNewTables) || in_array($table, $allowedNewTables)); |
||
| 765 | } |
||
| 766 | |||
| 767 | /** |
||
| 768 | * @return LanguageService |
||
| 769 | */ |
||
| 770 | protected function getLanguageService(): LanguageService |
||
| 771 | { |
||
| 772 | return $GLOBALS['LANG']; |
||
| 773 | } |
||
| 774 | |||
| 775 | /** |
||
| 776 | * @return BackendUserAuthentication |
||
| 777 | */ |
||
| 778 | protected function getBackendUserAuthentication(): BackendUserAuthentication |
||
| 781 | } |
||
| 782 | } |
||
| 783 |