2929use TYPO3 \CMS \Core \Database \Query \Restriction \HiddenRestriction ;
3030use TYPO3 \CMS \Core \Database \Query \Restriction \RootLevelRestriction ;
3131use TYPO3 \CMS \Core \Database \Query \Restriction \WorkspaceRestriction ;
32+ use TYPO3 \CMS \Core \DataHandling \TableColumnType ;
3233use TYPO3 \CMS \Core \FormProtection \FormProtectionFactory ;
3334use TYPO3 \CMS \Core \Http \ImmediateResponseException ;
3435use TYPO3 \CMS \Core \Http \RedirectResponse ;
3536use TYPO3 \CMS \Core \Package \PackageManager ;
3637use TYPO3 \CMS \Core \Resource \Filter \FileNameFilter ;
3738use TYPO3 \CMS \Core \Resource \StorageRepository ;
3839use TYPO3 \CMS \Core \Routing \BackendEntryPointResolver ;
40+ use TYPO3 \CMS \Core \Schema \Capability \TcaSchemaCapability ;
41+ use TYPO3 \CMS \Core \Schema \TcaSchema ;
42+ use TYPO3 \CMS \Core \Schema \TcaSchemaFactory ;
3943use TYPO3 \CMS \Core \Site \Entity \SiteLanguage ;
4044use TYPO3 \CMS \Core \SysLog \Action as SystemLogGenericAction ;
4145use TYPO3 \CMS \Core \SysLog \Error as SystemLogErrorClassification ;
@@ -321,6 +325,10 @@ public function isInWebMount($idOrRow, $readPerms = '')
321325 if ($ this ->isAdmin ()) {
322326 return 1 ;
323327 }
328+ $ schema = GeneralUtility::makeInstance (TcaSchemaFactory::class)->get ('pages ' );
329+ $ languageCapability = $ schema ->getCapability (TcaSchemaCapability::Language);
330+ $ languageFieldName = $ languageCapability ->getLanguageField ()->getName ();
331+ $ transOrigPointerFieldName = $ languageCapability ->getTranslationOriginPointerField ()->getName ();
324332 $ checkRec = [];
325333 $ fetchPageFromDatabase = true ;
326334 if (is_array ($ idOrRow )) {
@@ -330,7 +338,7 @@ public function isInWebMount($idOrRow, $readPerms = '')
330338 $ checkRec = $ idOrRow ;
331339 $ id = (int )$ idOrRow ['uid ' ];
332340 // ensure the required fields are present on the record
333- if (isset ($ checkRec ['t3ver_oid ' ], $ checkRec [$ GLOBALS [ ' TCA ' ][ ' pages ' ][ ' ctrl ' ][ ' languageField ' ]] , $ checkRec [$ GLOBALS [ ' TCA ' ][ ' pages ' ][ ' ctrl ' ][ ' transOrigPointerField ' ] ])) {
341+ if (isset ($ checkRec ['t3ver_oid ' ], $ checkRec [$ languageFieldName ] , $ checkRec [$ transOrigPointerFieldName ])) {
334342 $ fetchPageFromDatabase = false ;
335343 }
336344 } else {
@@ -341,18 +349,19 @@ public function isInWebMount($idOrRow, $readPerms = '')
341349 $ checkRec = BackendUtility::getRecord (
342350 'pages ' ,
343351 $ id ,
344- 't3ver_oid, ' . $ GLOBALS [ ' TCA ' ][ ' pages ' ][ ' ctrl ' ][ ' transOrigPointerField ' ] . ', ' . $ GLOBALS [ ' TCA ' ][ ' pages ' ][ ' ctrl ' ][ ' languageField ' ]
352+ 't3ver_oid, ' . $ transOrigPointerFieldName . ', ' . $ languageFieldName
345353 );
346354 }
355+ if (!is_array ($ checkRec )) {
356+ return null ;
357+ }
347358 if ((int )($ checkRec ['t3ver_oid ' ] ?? 0 ) > 0 ) {
348359 $ id = (int )$ checkRec ['t3ver_oid ' ];
349360 }
350361 // if current rec is a translation then get uid from l10n_parent instead
351362 // because web mounts point to pages in default language and rootline returns uids of default languages
352- if ((int )($ checkRec [$ GLOBALS ['TCA ' ]['pages ' ]['ctrl ' ]['languageField ' ] ?? null ] ?? 0 ) !== 0
353- && (int )($ checkRec [$ GLOBALS ['TCA ' ]['pages ' ]['ctrl ' ]['transOrigPointerField ' ] ?? null ] ?? 0 ) !== 0
354- ) {
355- $ id = (int )$ checkRec [$ GLOBALS ['TCA ' ]['pages ' ]['ctrl ' ]['transOrigPointerField ' ]];
363+ if ((int )($ checkRec [$ languageFieldName ]) !== 0 && (int )($ checkRec [$ transOrigPointerFieldName ]) !== 0 ) {
364+ $ id = (int )$ checkRec [$ transOrigPointerFieldName ];
356365 }
357366 if (!$ readPerms ) {
358367 $ readPerms = $ this ->getPagePermsClause (Permission::PAGE_SHOW );
@@ -600,18 +609,26 @@ public function checkLanguageAccess($langValue)
600609 /**
601610 * Check if user has access to all existing localizations for a certain record
602611 *
603- * @param string $table The table
612+ * @param string|TcaSchema $table The table/schema
604613 * @param array $record The current record
605614 * @return bool
606615 */
607- public function checkFullLanguagesAccess (string $ table , array $ record ): bool
616+ public function checkFullLanguagesAccess (string | TcaSchema $ table , array $ record ): bool
608617 {
609618 if (!$ this ->checkLanguageAccess (0 )) {
610619 return false ;
611620 }
621+ if ($ table instanceof TcaSchema) {
622+ $ schema = $ table ;
623+ $ table = $ table ->getName ();
624+ } else {
625+ $ schema = GeneralUtility::makeInstance (TcaSchemaFactory::class)->get ($ table );
626+ }
612627
613- if (BackendUtility::isTableLocalizable ($ table )) {
614- $ pointerField = $ GLOBALS ['TCA ' ][$ table ]['ctrl ' ]['transOrigPointerField ' ];
628+ if ($ schema ->isLanguageAware ()) {
629+ $ languageCapability = $ schema ->getCapability (TcaSchemaCapability::Language);
630+ $ languageField = $ languageCapability ->getLanguageField ()->getName ();
631+ $ pointerField = $ languageCapability ->getTranslationOriginPointerField ()->getName ();
615632 $ pointerValue = $ record [$ pointerField ] > 0 ? $ record [$ pointerField ] : $ record ['uid ' ];
616633 $ queryBuilder = GeneralUtility::makeInstance (ConnectionPool::class)->getQueryBuilderForTable ($ table );
617634 $ queryBuilder ->getRestrictions ()
@@ -630,7 +647,7 @@ public function checkFullLanguagesAccess(string $table, array $record): bool
630647 ->fetchAllAssociative ();
631648
632649 foreach ($ recordLocalizations as $ recordLocalization ) {
633- if (!$ this ->checkLanguageAccess ($ recordLocalization [$ GLOBALS [ ' TCA ' ][ $ table ][ ' ctrl ' ][ ' languageField ' ] ])) {
650+ if (!$ this ->checkLanguageAccess ($ recordLocalization [$ languageField ])) {
634651 return false ;
635652 }
636653 }
@@ -656,60 +673,63 @@ public function checkFullLanguagesAccess(string $table, array $record): bool
656673 */
657674 public function recordEditAccessInternals (string $ table , array $ row , $ newRecord = false , $ _ = null , $ checkFullLanguageAccess = false ): bool
658675 {
659- if (!isset ($ GLOBALS ['TCA ' ][$ table ])) {
676+ $ schemaFactory = GeneralUtility::makeInstance (TcaSchemaFactory::class);
677+ if (!$ schemaFactory ->has ($ table )) {
660678 return false ;
661679 }
680+ $ schema = $ schemaFactory ->get ($ table );
662681 // Always return TRUE for Admin users.
663682 if ($ this ->isAdmin ()) {
664683 return true ;
665684 }
666685 // Checking languages:
667- if ($ table === 'pages ' && $ checkFullLanguageAccess && !$ this ->checkFullLanguagesAccess ($ table , $ row )) {
686+ if ($ table === 'pages ' && $ checkFullLanguageAccess && !$ this ->checkFullLanguagesAccess ($ schema , $ row )) {
668687 return false ;
669688 }
670- if ($ GLOBALS ['TCA ' ][$ table ]['ctrl ' ]['languageField ' ] ?? false ) {
689+ if ($ schema ->isLanguageAware ()) {
690+ $ languageCapability = $ schema ->getCapability (TcaSchemaCapability::Language);
691+ $ languageField = $ languageCapability ->getLanguageField ()->getName ();
692+
671693 // Language field must be found in input row - otherwise it does not make sense.
672- if (isset ($ row [$ GLOBALS [ ' TCA ' ][ $ table ][ ' ctrl ' ][ ' languageField ' ] ])) {
673- if (!$ this ->checkLanguageAccess ($ row [$ GLOBALS [ ' TCA ' ][ $ table ][ ' ctrl ' ][ ' languageField ' ] ])) {
694+ if (isset ($ row [$ languageField ])) {
695+ if (!$ this ->checkLanguageAccess ($ row [$ languageField ])) {
674696 $ this ->errorMsg = 'ERROR: Language was not allowed. ' ;
675697 return false ;
676698 }
677699 if (
678- $ checkFullLanguageAccess && $ row [$ GLOBALS [ ' TCA ' ][ $ table ][ ' ctrl ' ][ ' languageField ' ] ] == 0
700+ $ checkFullLanguageAccess && $ row [$ languageField ] == 0
679701 && !$ this ->checkFullLanguagesAccess ($ table , $ row )
680702 ) {
681703 $ this ->errorMsg = 'ERROR: Related/affected language was not allowed. ' ;
682704 return false ;
683705 }
684706 } else {
685- $ this ->errorMsg = 'ERROR: The "languageField" field named " '
686- . $ GLOBALS ['TCA ' ][$ table ]['ctrl ' ]['languageField ' ] . '" was not found in testing record! ' ;
707+ $ this ->errorMsg = 'ERROR: The "languageField" field named " ' . $ languageField . '" was not found in testing record! ' ;
687708 return false ;
688709 }
689710 }
690711 // Checking authMode fields:
691- if (is_array ($ GLOBALS ['TCA ' ][$ table ]['columns ' ])) {
692- foreach ($ GLOBALS ['TCA ' ][$ table ]['columns ' ] as $ fieldName => $ fieldValue ) {
693- if (isset ($ row [$ fieldName ])
694- && ($ fieldValue ['config ' ]['type ' ] ?? '' ) === 'select '
695- && ($ fieldValue ['config ' ]['authMode ' ] ?? false )
696- && !$ this ->checkAuthMode ($ table , $ fieldName , $ row [$ fieldName ])) {
697- $ this ->errorMsg = 'ERROR: authMode " ' . $ fieldValue ['config ' ]['authMode ' ]
698- . '" failed for field " ' . $ fieldName . '" with value " '
699- . $ row [$ fieldName ] . '" evaluated ' ;
700- return false ;
701- }
712+ foreach ($ schema ->getFields () as $ fieldName => $ fieldType ) {
713+ if (isset ($ row [$ fieldName ])
714+ && $ fieldType ->isType (TableColumnType::SELECT )
715+ && ($ fieldType ->getConfiguration ()['authMode ' ] ?? false )
716+ && !$ this ->checkAuthMode ($ table , $ fieldName , $ row [$ fieldName ])) {
717+ $ this ->errorMsg = 'ERROR: authMode " ' . $ fieldType ->getConfiguration ()['authMode ' ]
718+ . '" failed for field " ' . $ fieldName . '" with value " '
719+ . $ row [$ fieldName ] . '" evaluated ' ;
720+ return false ;
702721 }
703722 }
704723 // Checking "editlock" feature (doesn't apply to new records)
705- if (!$ newRecord && ($ GLOBALS ['TCA ' ][$ table ]['ctrl ' ]['editlock ' ] ?? false )) {
706- if (isset ($ row [$ GLOBALS ['TCA ' ][$ table ]['ctrl ' ]['editlock ' ]])) {
707- if ($ row [$ GLOBALS ['TCA ' ][$ table ]['ctrl ' ]['editlock ' ]]) {
724+ if (!$ newRecord && $ schema ->hasCapability (TcaSchemaCapability::EditLock)) {
725+ $ editLockFieldName = $ schema ->getCapability (TcaSchemaCapability::EditLock)->getFieldName ();
726+ if (isset ($ row [$ editLockFieldName ])) {
727+ if ($ row [$ editLockFieldName ]) {
708728 $ this ->errorMsg = 'ERROR: Record was locked for editing. Only admin users can change this state. ' ;
709729 return false ;
710730 }
711731 } else {
712- $ this ->errorMsg = 'ERROR: The "editLock" field named " ' . $ GLOBALS [ ' TCA ' ][ $ table ][ ' ctrl ' ][ ' editlock ' ]
732+ $ this ->errorMsg = 'ERROR: The "editLock" field named " ' . $ editLockFieldName
713733 . '" was not found in testing record! ' ;
714734 return false ;
715735 }
0 commit comments