2 namespace TYPO3\CMS\Core\DataHandling
;
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 Doctrine\DBAL\DBALException
;
18 use Doctrine\DBAL\Driver\Statement
;
19 use Doctrine\DBAL\Platforms\PostgreSqlPlatform
;
20 use Doctrine\DBAL\Platforms\SqlitePlatform
;
21 use Doctrine\DBAL\Platforms\SQLServerPlatform
;
22 use Doctrine\DBAL\Types\IntegerType
;
23 use Psr\Log\LoggerAwareInterface
;
24 use Psr\Log\LoggerAwareTrait
;
25 use TYPO3\CMS\Backend\Utility\BackendUtility
;
26 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication
;
27 use TYPO3\CMS\Core\Cache\CacheManager
;
28 use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
;
29 use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait
;
30 use TYPO3\CMS\Core\Configuration\FlexForm\Exception\InvalidIdentifierException
;
31 use TYPO3\CMS\Core\Configuration\FlexForm\Exception\InvalidParentRowException
;
32 use TYPO3\CMS\Core\Configuration\FlexForm\Exception\InvalidParentRowLoopException
;
33 use TYPO3\CMS\Core\Configuration\FlexForm\Exception\InvalidParentRowRootException
;
34 use TYPO3\CMS\Core\Configuration\FlexForm\Exception\InvalidPointerFieldValueException
;
35 use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools
;
36 use TYPO3\CMS\Core\Configuration\Richtext
;
37 use TYPO3\CMS\Core\Core\Environment
;
38 use TYPO3\CMS\Core\Database\Connection
;
39 use TYPO3\CMS\Core\Database\ConnectionPool
;
40 use TYPO3\CMS\Core\Database\Query\QueryHelper
;
41 use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction
;
42 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
;
43 use TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionContainerInterface
;
44 use TYPO3\CMS\Core\Database\ReferenceIndex
;
45 use TYPO3\CMS\Core\Database\RelationHandler
;
46 use TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore
;
47 use TYPO3\CMS\Core\DataHandling\Localization\DataMapProcessor
;
48 use TYPO3\CMS\Core\Html\RteHtmlParser
;
49 use TYPO3\CMS\Core\Localization\LanguageService
;
50 use TYPO3\CMS\Core\Messaging\FlashMessage
;
51 use TYPO3\CMS\Core\Messaging\FlashMessageService
;
52 use TYPO3\CMS\Core\
Resource\ResourceFactory
;
53 use TYPO3\CMS\Core\Service\OpcodeCacheService
;
54 use TYPO3\CMS\Core\Type\Bitmask\Permission
;
55 use TYPO3\CMS\Core\Utility\ArrayUtility
;
56 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility
;
57 use TYPO3\CMS\Core\Utility\File\BasicFileUtility
;
58 use TYPO3\CMS\Core\Utility\GeneralUtility
;
59 use TYPO3\CMS\Core\Utility\MathUtility
;
60 use TYPO3\CMS\Core\Utility\PathUtility
;
61 use TYPO3\CMS\Core\Utility\StringUtility
;
62 use TYPO3\CMS\Core\Versioning\VersionState
;
63 use TYPO3\CMS\Saltedpasswords\Salt\SaltFactory
;
66 * The main data handler class which takes care of correctly updating and inserting records.
67 * This class was formerly known as TCEmain.
69 * This is the TYPO3 Core Engine class for manipulation of the database
70 * This class is used by eg. the tce_db BE route (SimpleDataHandlerController) which provides an the interface for POST forms to this class.
73 * - $GLOBALS['TCA'] must exist
74 * - $GLOBALS['LANG'] must exist
76 * Also see document 'TYPO3 Core API' for details.
78 class DataHandler
implements LoggerAwareInterface
81 use PublicPropertyDeprecationTrait
;
86 protected $deprecatedPublicProperties = [
87 'updateModeL10NdiffData' => 'Using updateModeL10NdiffData is deprecated and will not be possible anymore in TYPO3 v10.',
88 'updateModeL10NdiffDataClear' => 'Using updateModeL10NdiffDataClear is deprecated and will not be possible anymore in TYPO3 v10.',
91 // *********************
92 // Public variables you can configure before using the class:
93 // *********************
95 * If TRUE, the default log-messages will be stored. This should not be necessary if the locallang-file for the
96 * log-display is properly configured. So disabling this will just save some database-space as the default messages are not saved.
100 public $storeLogMessages = true;
103 * If TRUE, actions are logged to sys_log.
107 public $enableLogging = true;
110 * If TRUE, the datamap array is reversed in the order, which is a nice thing if you're creating a whole new
115 public $reverseOrder = false;
118 * If TRUE, only fields which are different from the database values are saved! In fact, if a whole input array
119 * is similar, it's not saved then.
123 public $checkSimilar = true;
126 * This will read the record after having updated or inserted it. If anything is not properly submitted an error
127 * is written to the log. This feature consumes extra time by selecting records
131 public $checkStoredRecords = true;
134 * If set, values '' and 0 will equal each other when the stored records are checked.
138 public $checkStoredRecords_loose = true;
141 * If this is set, then a page is deleted by deleting the whole branch under it (user must have
142 * delete permissions to it all). If not set, then the page is deleted ONLY if it has no branch.
146 public $deleteTree = false;
149 * If set, then the 'hideAtCopy' flag for tables will be ignored.
153 public $neverHideAtCopy = false;
156 * If set, then the TCE class has been instantiated during an import action of a T3D
160 public $isImporting = false;
163 * If set, then transformations are NOT performed on the input.
167 public $dontProcessTransformations = false;
170 * Will distinguish between translations (with parent) and localizations (without parent) while still using the same methods to copy the records
171 * TRUE: translation of a record connected to the default language
172 * FALSE: localization of a record without connection to the default language
176 protected $useTransOrigPointerField = true;
179 * TRUE: (traditional) Updates when record is saved. For flexforms, updates if change is made to the localized value.
180 * FALSE: Will not update anything.
181 * "FORCE_FFUPD" (string): Like TRUE, but will force update to the FlexForm Field
185 protected $updateModeL10NdiffData = true;
188 * If TRUE, the translation diff. fields will in fact be reset so that they indicate that all needs to change again!
189 * It's meant as the opposite of declaring the record translated.
193 protected $updateModeL10NdiffDataClear = false;
196 * If TRUE, workspace restrictions are bypassed on edit an create actions (process_datamap()).
197 * YOU MUST KNOW what you do if you use this feature!
201 public $bypassWorkspaceRestrictions = false;
204 * If TRUE, file handling of attached files (addition, deletion etc) is bypassed - the value is saved straight away.
205 * YOU MUST KNOW what you are doing with this feature!
209 public $bypassFileHandling = false;
212 * If TRUE, access check, check for deleted etc. for records is bypassed.
213 * YOU MUST KNOW what you are doing if you use this feature!
217 public $bypassAccessCheckForRecords = false;
220 * Comma-separated list. This list of tables decides which tables will be copied. If empty then none will.
221 * If '*' then all will (that the user has permission to of course)
225 public $copyWhichTables = '*';
228 * If 0 then branch is NOT copied.
229 * If 1 then pages on the 1st level is copied.
230 * If 2 then pages on the second level is copied ... and so on
234 public $copyTree = 0;
237 * [table][fields]=value: New records are created with default values and you can set this array on the
238 * form $defaultValues[$table][$field] = $value to override the default values fetched from TCA.
239 * If ->setDefaultsFromUserTS is called UserTSconfig default values will overrule existing values in this array
240 * (thus UserTSconfig overrules externally set defaults which overrules TCA defaults)
244 public $defaultValues = [];
247 * [table][fields]=value: You can set this array on the form $overrideValues[$table][$field] = $value to
248 * override the incoming data. You must set this externally. You must make sure the fields in this array are also
249 * found in the table, because it's not checked. All columns can be set by this array!
253 public $overrideValues = [];
256 * [filename]=alternative_filename: Use this array to force another name onto a file.
257 * Eg. if you set ['/tmp/blablabal'] = 'my_file.txt' and '/tmp/blablabal' is set for a certain file-field,
258 * then 'my_file.txt' will be used as the name instead.
262 public $alternativeFileName = [];
265 * Array [filename]=alternative_filepath: Same as alternativeFileName but with relative path to the file
269 public $alternativeFilePath = [];
272 * If entries are set in this array corresponding to fields for update, they are ignored and thus NOT updated.
273 * You could set this array from a series of checkboxes with value=0 and hidden fields before the checkbox with 1.
274 * Then an empty checkbox will disable the field.
278 public $data_disableFields = [];
281 * Use this array to validate suggested uids for tables by setting [table]:[uid]. This is a dangerous option
282 * since it will force the inserted record to have a certain UID. The value just have to be TRUE, but if you set
283 * it to "DELETE" it will make sure any record with that UID will be deleted first (raw delete).
284 * The option is used for import of T3D files when synchronizing between two mirrored servers.
285 * As a security measure this feature is available only for Admin Users (for now)
289 public $suggestedInsertUids = [];
292 * Object. Call back object for FlexForm traversal. Useful when external classes wants to use the
293 * iteration functions inside DataHandler for traversing a FlexForm structure.
299 // *********************
300 // Internal variables (mapping arrays) which can be used (read-only) from outside
301 // *********************
303 * Contains mapping of auto-versionized records.
307 public $autoVersionIdMap = [];
310 * When new elements are created, this array contains a map between their "NEW..." string IDs and the eventual UID they got when stored in database
314 public $substNEWwithIDs = [];
317 * Like $substNEWwithIDs, but where each old "NEW..." id is mapped to the table it was from.
321 public $substNEWwithIDs_table = [];
324 * Holds the tables and there the ids of newly created child records from IRRE
328 public $newRelatedIDs = [];
331 * This array is the sum of all copying operations in this class. May be READ from outside, thus partly public.
335 public $copyMappingArray_merged = [];
338 * Per-table array with UIDs that have been deleted.
342 protected $deletedRecords = [];
345 * A map between input file name and final destination for files being attached to records.
349 public $copiedFileMap = [];
352 * Contains [table][id][field] of fiels where RTEmagic images was copied. Holds old filename as key and new filename as value.
356 public $RTEmagic_copyIndex = [];
359 * Errors are collected in this variable.
363 public $errorLog = [];
366 * Fields from the pages-table for which changes will trigger a pagetree refresh
370 public $pagetreeRefreshFieldsFromPages = ['pid', 'sorting', 'deleted', 'hidden', 'title', 'doktype', 'is_siteroot', 'fe_group', 'nav_hide', 'nav_title', 'module', 'starttime', 'endtime', 'content_from_pid', 'extendToSubpages'];
373 * Indicates whether the pagetree needs a refresh because of important changes
377 public $pagetreeNeedsRefresh = false;
379 // *********************
380 // Internal Variables, do not touch.
381 // *********************
383 // Variables set in init() function:
386 * The user-object the script uses. If not set from outside, this is set to the current global $BE_USER.
388 * @var BackendUserAuthentication
393 * Will be set to uid of be_user executing this script
400 * Will be set to username of be_user executing this script
407 * Will be set if user is admin
414 * Can be overridden from $GLOBALS['TYPO3_CONF_VARS']
418 public $defaultPermissions = [
419 'user' => 'show,edit,delete,new,editcontent',
420 'group' => 'show,edit,new,editcontent',
425 * The list of <table>-<fields> that cannot be edited by user. This is compiled from TCA/exclude-flag combined with non_exclude_fields for the user.
429 protected $excludedTablesAndFields = [];
432 * Data submitted from the form view, used to control behaviours,
433 * e.g. this is used to activate/deactivate fields and thus store NULL values
437 protected $control = [];
440 * Set with incoming data array
444 public $datamap = [];
447 * Set with incoming cmd array
454 * List of changed old record ids to new records ids
458 protected $mmHistoryRecords = [];
461 * List of changed old record ids to new records ids
465 protected $historyRecords = [];
486 * Integer: The interval between sorting numbers used with tables with a 'sorting' field defined. Min 1
490 public $sortIntervals = 256;
492 // Internal caching arrays
494 * Used by function checkRecordUpdateAccess() to store whether a record is updatable or not.
498 protected $recUpdateAccessCache = [];
501 * User by function checkRecordInsertAccess() to store whether a record can be inserted on a page id
505 protected $recInsertAccessCache = [];
508 * Caching array for check of whether records are in a webmount
512 protected $isRecordInWebMount_Cache = [];
515 * Caching array for page ids in webmounts
519 protected $isInWebMount_Cache = [];
522 * Used for caching page records in pageInfo()
526 protected $pageCache = [];
530 * For accumulation of MM relations that must be written after new records are created.
534 public $dbAnalysisStore = [];
537 * For accumulation of files which must be deleted after processing of all input content
541 public $removeFilesStore = [];
544 * Uploaded files, set by process_uploads()
548 public $uploadedFileArray = [];
551 * Used for tracking references that might need correction after operations
555 public $registerDBList = [];
558 * Used for tracking references that might need correction in pid field after operations (e.g. IRRE)
562 public $registerDBPids = [];
565 * Used by the copy action to track the ids of new pages so subpages are correctly inserted!
566 * THIS is internally cleared for each executed copy operation! DO NOT USE THIS FROM OUTSIDE!
567 * Read from copyMappingArray_merged instead which is accumulating this information.
569 * NOTE: This is used by some outside scripts (e.g. hooks), as the results in $copyMappingArray_merged
570 * are only available after an action has been completed.
574 public $copyMappingArray = [];
577 * Array used for remapping uids and values at the end of process_datamap
581 public $remapStack = [];
584 * Array used for remapping uids and values at the end of process_datamap
585 * (e.g. $remapStackRecords[<table>][<uid>] = <index in $remapStack>)
589 public $remapStackRecords = [];
592 * Array used for checking whether new children need to be remapped
596 protected $remapStackChildIds = [];
599 * Array used for executing addition actions after remapping happened (set processRemapStack())
603 protected $remapStackActions = [];
606 * Array used for executing post-processing on the reference index
610 protected $remapStackRefIndex = [];
613 * Array used for additional calls to $this->updateRefIndex
617 public $updateRefIndexStack = [];
620 * Tells, that this DataHandler instance was called from \TYPO3\CMS\Impext\ImportExport.
621 * This variable is set by \TYPO3\CMS\Impext\ImportExport
625 public $callFromImpExp = false;
629 * basicFileFunctions object
630 * For "singleton" file-manipulation object
632 * @var BasicFileUtility
637 * Set to "currentRecord" during checking of values.
641 public $checkValue_currentRecord = [];
644 * A signal flag used to tell file processing that auto versioning has happened and hence certain action should be applied.
648 public $autoVersioningUpdate = false;
651 * Disable delete clause
655 protected $disableDeleteClause = false;
660 protected $checkModifyAccessListHookObjects;
665 protected $version_remapMMForVersionSwap_reg;
668 * The outer most instance of \TYPO3\CMS\Core\DataHandling\DataHandler:
669 * This object instantiates itself on versioning and localization ...
671 * @var \TYPO3\CMS\Core\DataHandling\DataHandler
673 protected $outerMostInstance;
676 * Internal cache for collecting records that should trigger cache clearing
680 protected static $recordsToClearCacheFor = [];
683 * Internal cache for pids of records which were deleted. It's not possible
684 * to retrieve the parent folder/page at a later stage
688 protected static $recordPidsForDeletedRecords = [];
691 * Runtime Cache to store and retrieve data computed for a single request
693 * @var \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
695 protected $runtimeCache;
698 * Prefix for the cache entries of nested element calls since the runtimeCache has a global scope.
702 protected $cachePrefixNestedElementCalls = 'core-datahandler-nestedElementCalls-';
705 * Sets up the data handler cache and some additional options, the main logic is done in the start() method.
707 public function __construct()
709 $this->checkStoredRecords
= (bool)$GLOBALS['TYPO3_CONF_VARS']['BE']['checkStoredRecords'];
710 $this->checkStoredRecords_loose
= (bool)$GLOBALS['TYPO3_CONF_VARS']['BE']['checkStoredRecordsLoose'];
711 $this->runtimeCache
= $this->getRuntimeCache();
715 * @param array $control
717 public function setControl(array $control)
719 $this->control
= $control;
724 * For details, see 'TYPO3 Core API' document.
725 * This function does not start the processing of data, but merely initializes the object
727 * @param array $data Data to be modified or inserted in the database
728 * @param array $cmd Commands to copy, move, delete, localize, versionize records.
729 * @param BackendUserAuthentication|null $altUserObject An alternative userobject you can set instead of the default, which is $GLOBALS['BE_USER']
731 public function start($data, $cmd, $altUserObject = null)
733 // Initializing BE_USER
734 $this->BE_USER
= is_object($altUserObject) ?
$altUserObject : $GLOBALS['BE_USER'];
735 $this->userid
= $this->BE_USER
->user
['uid'];
736 $this->username
= $this->BE_USER
->user
['username'];
737 $this->admin
= $this->BE_USER
->user
['admin'];
738 if ($this->BE_USER
->uc
['recursiveDelete']) {
739 $this->deleteTree
= 1;
741 // Initializing default permissions for pages
742 $defaultPermissions = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPermissions'];
743 if (isset($defaultPermissions['user'])) {
744 $this->defaultPermissions
['user'] = $defaultPermissions['user'];
746 if (isset($defaultPermissions['group'])) {
747 $this->defaultPermissions
['group'] = $defaultPermissions['group'];
749 if (isset($defaultPermissions['everybody'])) {
750 $this->defaultPermissions
['everybody'] = $defaultPermissions['everybody'];
752 // generates the excludelist, based on TCA/exclude-flag and non_exclude_fields for the user:
754 $this->excludedTablesAndFields
= array_flip($this->getExcludeListArray());
756 // Setting the data and cmd arrays
757 if (is_array($data)) {
759 $this->datamap
= $data;
761 if (is_array($cmd)) {
763 $this->cmdmap
= $cmd;
768 * Function that can mirror input values in datamap-array to other uid numbers.
769 * Example: $mirror[table][11] = '22,33' will look for content in $this->datamap[table][11] and copy it to $this->datamap[table][22] and $this->datamap[table][33]
771 * @param array $mirror This array has the syntax $mirror[table_name][uid] = [list of uids to copy data-value TO!]
773 public function setMirror($mirror)
775 if (!is_array($mirror)) {
779 foreach ($mirror as $table => $uid_array) {
780 if (!isset($this->datamap
[$table])) {
784 foreach ($uid_array as $id => $uidList) {
785 if (!isset($this->datamap
[$table][$id])) {
789 $theIdsInArray = GeneralUtility
::trimExplode(',', $uidList, true);
790 foreach ($theIdsInArray as $copyToUid) {
791 $this->datamap
[$table][$copyToUid] = $this->datamap
[$table][$id];
798 * Initializes default values coming from User TSconfig
800 * @param array $userTS User TSconfig array
802 public function setDefaultsFromUserTS($userTS)
804 if (!is_array($userTS)) {
808 foreach ($userTS as $k => $v) {
809 $k = mb_substr($k, 0, -1);
810 if (!$k ||
!is_array($v) ||
!isset($GLOBALS['TCA'][$k])) {
814 if (is_array($this->defaultValues
[$k])) {
815 $this->defaultValues
[$k] = array_merge($this->defaultValues
[$k], $v);
817 $this->defaultValues
[$k] = $v;
823 * Processing of uploaded files.
824 * It turns out that some versions of PHP arranges submitted data for files different if sent in an array. This function will unify this so the internal array $this->uploadedFileArray will always contain files arranged in the same structure.
826 * @param array $postFiles $_FILES array
828 public function process_uploads($postFiles)
830 if (!is_array($postFiles)) {
835 if ($this->BE_USER
->workspace
!== 0 && $this->BE_USER
->workspaceRec
['freeze']) {
836 $this->newlog('All editing in this workspace has been frozen!', 1);
839 $subA = reset($postFiles);
840 if (is_array($subA)) {
841 if (is_array($subA['name']) && is_array($subA['type']) && is_array($subA['tmp_name']) && is_array($subA['size'])) {
842 // Initialize the uploadedFilesArray:
843 $this->uploadedFileArray
= [];
845 foreach ($subA as $key => $values) {
846 $this->process_uploads_traverseArray($this->uploadedFileArray
, $values, $key);
849 $this->uploadedFileArray
= $subA;
855 * Traverse the upload array if needed to rearrange values.
857 * @param array $outputArr $this->uploadedFileArray passed by reference
858 * @param array $inputArr Input array ($_FILES parts)
859 * @param string $keyToSet The current $_FILES array key to set on the outermost level.
861 * @see process_uploads()
863 public function process_uploads_traverseArray(&$outputArr, $inputArr, $keyToSet)
865 if (is_array($inputArr)) {
866 foreach ($inputArr as $key => $value) {
867 $this->process_uploads_traverseArray($outputArr[$key], $inputArr[$key], $keyToSet);
870 $outputArr[$keyToSet] = $inputArr;
874 /*********************************************
878 *********************************************/
880 * Hook: processDatamap_afterDatabaseOperations
881 * (calls $hookObj->processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $this);)
883 * Note: When using the hook after INSERT operations, you will only get the temporary NEW... id passed to your hook as $id,
884 * but you can easily translate it to the real uid of the inserted record using the $this->substNEWwithIDs array.
886 * @param array $hookObjectsArr (reference) Array with hook objects
887 * @param string $status (reference) Status of the current operation, 'new' or 'update
888 * @param string $table (reference) The table currently processing data for
889 * @param string $id (reference) The record uid currently processing data for, [integer] or [string] (like 'NEW...')
890 * @param array $fieldArray (reference) The field array of a record
892 public function hook_processDatamap_afterDatabaseOperations(&$hookObjectsArr, &$status, &$table, &$id, &$fieldArray)
894 // Process hook directly:
895 if (!isset($this->remapStackRecords
[$table][$id])) {
896 foreach ($hookObjectsArr as $hookObj) {
897 if (method_exists($hookObj, 'processDatamap_afterDatabaseOperations')) {
898 $hookObj->processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $this);
902 $this->remapStackRecords
[$table][$id]['processDatamap_afterDatabaseOperations'] = [
904 'fieldArray' => $fieldArray,
905 'hookObjectsArr' => $hookObjectsArr
911 * Gets the 'checkModifyAccessList' hook objects.
912 * The first call initializes the accordant objects.
914 * @return array The 'checkModifyAccessList' hook objects (if any)
915 * @throws \UnexpectedValueException
917 protected function getCheckModifyAccessListHookObjects()
919 if (!isset($this->checkModifyAccessListHookObjects
)) {
920 $this->checkModifyAccessListHookObjects
= [];
921 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'] ??
[] as $className) {
922 $hookObject = GeneralUtility
::makeInstance($className);
923 if (!$hookObject instanceof DataHandlerCheckModifyAccessListHookInterface
) {
924 throw new \
UnexpectedValueException($className . ' must implement interface ' . DataHandlerCheckModifyAccessListHookInterface
::class, 1251892472);
926 $this->checkModifyAccessListHookObjects
[] = $hookObject;
929 return $this->checkModifyAccessListHookObjects
;
932 /*********************************************
936 *********************************************/
938 * Processing the data-array
939 * Call this function to process the data-array set by start()
943 public function process_datamap()
945 $this->controlActiveElements();
947 // Keep versionized(!) relations here locally:
948 $registerDBList = [];
949 $this->registerElementsToBeDeleted();
950 $this->datamap
= $this->unsetElementsToBeDeleted($this->datamap
);
952 if ($this->BE_USER
->workspace
!== 0 && $this->BE_USER
->workspaceRec
['freeze']) {
953 $this->newlog('All editing in this workspace has been frozen!', 1);
956 // First prepare user defined objects (if any) for hooks which extend this function:
957 $hookObjectsArr = [];
958 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'] ??
[] as $className) {
959 $hookObject = GeneralUtility
::makeInstance($className);
960 if (method_exists($hookObject, 'processDatamap_beforeStart')) {
961 $hookObject->processDatamap_beforeStart($this);
963 $hookObjectsArr[] = $hookObject;
965 // Pre-process data-map and synchronize localization states
966 $this->datamap
= DataMapProcessor
::instance($this->datamap
, $this->BE_USER
)->process();
967 // Organize tables so that the pages-table is always processed first. This is required if you want to make sure that content pointing to a new page will be created.
970 if (isset($this->datamap
['pages'])) {
971 $orderOfTables[] = 'pages';
973 $orderOfTables = array_unique(array_merge($orderOfTables, array_keys($this->datamap
)));
974 // Process the tables...
975 foreach ($orderOfTables as $table) {
977 // - table is set in $GLOBALS['TCA'],
978 // - table is NOT readOnly
979 // - the table is set with content in the data-array (if not, there's nothing to process...)
980 // - permissions for tableaccess OK
981 $modifyAccessList = $this->checkModifyAccessList($table);
982 if (!$modifyAccessList) {
983 $this->log($table, 0, 2, 0, 1, 'Attempt to modify table \'%s\' without permission', 1, [$table]);
985 if (!isset($GLOBALS['TCA'][$table]) ||
$this->tableReadOnly($table) ||
!is_array($this->datamap
[$table]) ||
!$modifyAccessList) {
989 if ($this->reverseOrder
) {
990 $this->datamap
[$table] = array_reverse($this->datamap
[$table], 1);
992 // For each record from the table, do:
993 // $id is the record uid, may be a string if new records...
994 // $incomingFieldArray is the array of fields
995 foreach ($this->datamap
[$table] as $id => $incomingFieldArray) {
996 if (!is_array($incomingFieldArray)) {
1001 // Hook: processDatamap_preProcessFieldArray
1002 foreach ($hookObjectsArr as $hookObj) {
1003 if (method_exists($hookObj, 'processDatamap_preProcessFieldArray')) {
1004 $hookObj->processDatamap_preProcessFieldArray($incomingFieldArray, $table, $id, $this);
1007 // ******************************
1008 // Checking access to the record
1009 // ******************************
1010 $createNewVersion = false;
1011 $recordAccess = false;
1012 $old_pid_value = '';
1013 $this->autoVersioningUpdate
= false;
1014 // Is it a new record? (Then Id is a string)
1015 if (!MathUtility
::canBeInterpretedAsInteger($id)) {
1016 // Get a fieldArray with default values
1017 $fieldArray = $this->newFieldArray($table);
1018 // A pid must be set for new records.
1019 if (isset($incomingFieldArray['pid'])) {
1020 $pid_value = $incomingFieldArray['pid'];
1021 // Checking and finding numerical pid, it may be a string-reference to another value
1024 if (strpos($pid_value, 'NEW') !== false) {
1025 if ($pid_value[0] === '-') {
1027 $pid_value = substr($pid_value, 1);
1031 // Trying to find the correct numerical value as it should be mapped by earlier processing of another new record.
1032 if (isset($this->substNEWwithIDs
[$pid_value])) {
1033 if ($negFlag === 1) {
1034 $old_pid_value = $this->substNEWwithIDs
[$pid_value];
1036 $pid_value = (int)($negFlag * $this->substNEWwithIDs
[$pid_value]);
1038 $canProceed = false;
1041 $pid_value = (int)$pid_value;
1043 $fieldArray = $this->resolveSortingAndPidForNewRecord($table, $pid_value, $fieldArray);
1046 $theRealPid = $fieldArray['pid'];
1047 // Now, check if we may insert records on this pid.
1048 if ($theRealPid >= 0) {
1049 // Checks if records can be inserted on this $pid.
1050 // If this is a page translation, the check needs to be done for the l10n_parent record
1051 if ($table === 'pages' && $incomingFieldArray[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0 && $incomingFieldArray[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] > 0) {
1052 $recordAccess = $this->checkRecordInsertAccess($table, $incomingFieldArray[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']]);
1054 $recordAccess = $this->checkRecordInsertAccess($table, $theRealPid);
1056 if ($recordAccess) {
1057 $this->addDefaultPermittedLanguageIfNotSet($table, $incomingFieldArray);
1058 $recordAccess = $this->BE_USER
->recordEditAccessInternals($table, $incomingFieldArray, true);
1059 if (!$recordAccess) {
1060 $this->newlog('recordEditAccessInternals() check failed. [' . $this->BE_USER
->errorMsg
. ']', 1);
1061 } elseif (!$this->bypassWorkspaceRestrictions
) {
1062 // Workspace related processing:
1063 // If LIVE records cannot be created in the current PID due to workspace restrictions, prepare creation of placeholder-record
1064 if ($res = $this->BE_USER
->workspaceAllowLiveRecordsInPID($theRealPid, $table)) {
1066 $recordAccess = false;
1067 $this->newlog('Stage for versioning root point and users access level did not allow for editing', 1);
1070 // So, if no live records were allowed, we have to create a new version of this record:
1071 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
1072 $createNewVersion = true;
1074 $recordAccess = false;
1075 $this->newlog('Record could not be created in this workspace in this branch', 1);
1081 $this->logger
->debug('Internal ERROR: pid should not be less than zero!');
1083 // Yes new record, change $record_status to 'insert'
1086 // Nope... $id is a number
1088 $recordAccess = $this->checkRecordUpdateAccess($table, $id, $incomingFieldArray, $hookObjectsArr);
1089 if (!$recordAccess) {
1090 if ($this->enableLogging
) {
1091 $propArr = $this->getRecordProperties($table, $id);
1092 $this->log($table, $id, 2, 0, 1, 'Attempt to modify record \'%s\' (%s) without permission. Or non-existing page.', 2, [$propArr['header'], $table . ':' . $id], $propArr['event_pid']);
1096 // Next check of the record permissions (internals)
1097 $recordAccess = $this->BE_USER
->recordEditAccessInternals($table, $id);
1098 if (!$recordAccess) {
1099 $this->newlog('recordEditAccessInternals() check failed. [' . $this->BE_USER
->errorMsg
. ']', 1);
1101 // Here we fetch the PID of the record that we point to...
1102 $tempdata = $this->recordInfo($table, $id, 'pid' . ($GLOBALS['TCA'][$table]['ctrl']['versioningWS'] ?
',t3ver_wsid,t3ver_stage' : ''));
1103 $theRealPid = $tempdata['pid'];
1104 // Use the new id of the versionized record we're trying to write to:
1105 // (This record is a child record of a parent and has already been versionized.)
1106 if ($this->autoVersionIdMap
[$table][$id]) {
1107 // For the reason that creating a new version of this record, automatically
1108 // created related child records (e.g. "IRRE"), update the accordant field:
1109 $this->getVersionizedIncomingFieldArray($table, $id, $incomingFieldArray, $registerDBList);
1110 // Use the new id of the copied/versionized record:
1111 $id = $this->autoVersionIdMap
[$table][$id];
1112 $recordAccess = true;
1113 $this->autoVersioningUpdate
= true;
1114 } elseif (!$this->bypassWorkspaceRestrictions
&& ($errorCode = $this->BE_USER
->workspaceCannotEditRecord($table, $tempdata))) {
1115 $recordAccess = false;
1116 // Versioning is required and it must be offline version!
1117 // Check if there already is a workspace version
1118 $WSversion = BackendUtility
::getWorkspaceVersionOfRecord($this->BE_USER
->workspace
, $table, $id, 'uid,t3ver_oid');
1120 $id = $WSversion['uid'];
1121 $recordAccess = true;
1122 } elseif ($this->BE_USER
->workspaceAllowAutoCreation($table, $id, $theRealPid)) {
1123 // new version of a record created in a workspace - so always refresh pagetree to indicate there is a change in the workspace
1124 $this->pagetreeNeedsRefresh
= true;
1126 /** @var $tce DataHandler */
1127 $tce = GeneralUtility
::makeInstance(__CLASS__
);
1128 $tce->enableLogging
= $this->enableLogging
;
1129 // Setting up command for creating a new version of the record:
1131 $cmd[$table][$id]['version'] = [
1133 // Default is to create a version of the individual records... element versioning that is.
1134 'label' => 'Auto-created for WS #' . $this->BE_USER
->workspace
1136 $tce->start([], $cmd);
1137 $tce->process_cmdmap();
1138 $this->errorLog
= array_merge($this->errorLog
, $tce->errorLog
);
1139 // If copying was successful, share the new uids (also of related children):
1140 if ($tce->copyMappingArray
[$table][$id]) {
1141 foreach ($tce->copyMappingArray
as $origTable => $origIdArray) {
1142 foreach ($origIdArray as $origId => $newId) {
1143 $this->uploadedFileArray
[$origTable][$newId] = $this->uploadedFileArray
[$origTable][$origId];
1144 $this->autoVersionIdMap
[$origTable][$origId] = $newId;
1147 ArrayUtility
::mergeRecursiveWithOverrule($this->RTEmagic_copyIndex
, $tce->RTEmagic_copyIndex
);
1148 // See where RTEmagic_copyIndex is used inside fillInFieldArray() for more information...
1149 // Update registerDBList, that holds the copied relations to child records:
1150 $registerDBList = array_merge($registerDBList, $tce->registerDBList
);
1151 // For the reason that creating a new version of this record, automatically
1152 // created related child records (e.g. "IRRE"), update the accordant field:
1153 $this->getVersionizedIncomingFieldArray($table, $id, $incomingFieldArray, $registerDBList);
1154 // Use the new id of the copied/versionized record:
1155 $id = $this->autoVersionIdMap
[$table][$id];
1156 $recordAccess = true;
1157 $this->autoVersioningUpdate
= true;
1159 $this->newlog('Could not be edited in offline workspace in the branch where found (failure state: \'' . $errorCode . '\'). Auto-creation of version failed!', 1);
1162 $this->newlog('Could not be edited in offline workspace in the branch where found (failure state: \'' . $errorCode . '\'). Auto-creation of version not allowed in workspace!', 1);
1166 // The default is 'update'
1169 // If access was granted above, proceed to create or update record:
1170 if (!$recordAccess) {
1174 // Here the "pid" is set IF NOT the old pid was a string pointing to a place in the subst-id array.
1175 list($tscPID) = BackendUtility
::getTSCpid($table, $id, $old_pid_value ?
$old_pid_value : $fieldArray['pid']);
1176 if ($status === 'new' && $table === 'pages') {
1177 $TSConfig = BackendUtility
::getPagesTSconfig($tscPID)['TCEMAIN.'] ??
[];
1178 if (isset($TSConfig['permissions.']) && is_array($TSConfig['permissions.'])) {
1179 $fieldArray = $this->setTSconfigPermissions($fieldArray, $TSConfig['permissions.']);
1182 // Processing of all fields in incomingFieldArray and setting them in $fieldArray
1183 $fieldArray = $this->fillInFieldArray($table, $id, $fieldArray, $incomingFieldArray, $theRealPid, $status, $tscPID);
1184 $newVersion_placeholderFieldArray = [];
1185 if ($createNewVersion) {
1186 // create a placeholder array with already processed field content
1187 $newVersion_placeholderFieldArray = $fieldArray;
1189 // NOTICE! All manipulation beyond this point bypasses both "excludeFields" AND possible "MM" relations / file uploads to field!
1190 // Forcing some values unto field array:
1191 // NOTICE: This overriding is potentially dangerous; permissions per field is not checked!!!
1192 $fieldArray = $this->overrideFieldArray($table, $fieldArray);
1193 if ($createNewVersion) {
1194 $newVersion_placeholderFieldArray = $this->overrideFieldArray($table, $newVersion_placeholderFieldArray);
1196 // Setting system fields
1197 if ($status === 'new') {
1198 if ($GLOBALS['TCA'][$table]['ctrl']['crdate']) {
1199 $fieldArray[$GLOBALS['TCA'][$table]['ctrl']['crdate']] = $GLOBALS['EXEC_TIME'];
1200 if ($createNewVersion) {
1201 $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['crdate']] = $GLOBALS['EXEC_TIME'];
1204 if ($GLOBALS['TCA'][$table]['ctrl']['cruser_id']) {
1205 $fieldArray[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']] = $this->userid
;
1206 if ($createNewVersion) {
1207 $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']] = $this->userid
;
1210 } elseif ($this->checkSimilar
) {
1211 // Removing fields which are equal to the current value:
1212 $fieldArray = $this->compareFieldArrayWithCurrentAndUnset($table, $id, $fieldArray);
1214 if ($GLOBALS['TCA'][$table]['ctrl']['tstamp'] && !empty($fieldArray)) {
1215 $fieldArray[$GLOBALS['TCA'][$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME'];
1216 if ($createNewVersion) {
1217 $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME'];
1220 // Set stage to "Editing" to make sure we restart the workflow
1221 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
1222 $fieldArray['t3ver_stage'] = 0;
1224 // Hook: processDatamap_postProcessFieldArray
1225 foreach ($hookObjectsArr as $hookObj) {
1226 if (method_exists($hookObj, 'processDatamap_postProcessFieldArray')) {
1227 $hookObj->processDatamap_postProcessFieldArray($status, $table, $id, $fieldArray, $this);
1230 // Performing insert/update. If fieldArray has been unset by some userfunction (see hook above), don't do anything
1231 // Kasper: Unsetting the fieldArray is dangerous; MM relations might be saved already and files could have been uploaded that are now "lost"
1232 if (is_array($fieldArray)) {
1233 if ($status === 'new') {
1234 if ($table === 'pages') {
1235 // for new pages always a refresh is needed
1236 $this->pagetreeNeedsRefresh
= true;
1239 // This creates a new version of the record with online placeholder and offline version
1240 if ($createNewVersion) {
1241 // new record created in a workspace - so always refresh pagetree to indicate there is a change in the workspace
1242 $this->pagetreeNeedsRefresh
= true;
1244 $newVersion_placeholderFieldArray['t3ver_label'] = 'INITIAL PLACEHOLDER';
1245 // Setting placeholder state value for temporary record
1246 $newVersion_placeholderFieldArray['t3ver_state'] = (string)new VersionState(VersionState
::NEW_PLACEHOLDER
);
1247 // Setting workspace - only so display of place holders can filter out those from other workspaces.
1248 $newVersion_placeholderFieldArray['t3ver_wsid'] = $this->BE_USER
->workspace
;
1249 $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['label']] = $this->getPlaceholderTitleForTableLabel($table);
1250 // Saving placeholder as 'original'
1251 $this->insertDB($table, $id, $newVersion_placeholderFieldArray, false);
1252 // For the actual new offline version, set versioning values to point to placeholder:
1253 $fieldArray['pid'] = -1;
1254 $fieldArray['t3ver_oid'] = $this->substNEWwithIDs
[$id];
1255 $fieldArray['t3ver_id'] = 1;
1256 // Setting placeholder state value for version (so it can know it is currently a new version...)
1257 $fieldArray['t3ver_state'] = (string)new VersionState(VersionState
::NEW_PLACEHOLDER_VERSION
);
1258 $fieldArray['t3ver_label'] = 'First draft version';
1259 $fieldArray['t3ver_wsid'] = $this->BE_USER
->workspace
;
1260 // When inserted, $this->substNEWwithIDs[$id] will be changed to the uid of THIS version and so the interface will pick it up just nice!
1261 $phShadowId = $this->insertDB($table, $id, $fieldArray, true, 0, true);
1263 // Processes fields of the placeholder record:
1264 $this->triggerRemapAction($table, $id, [$this, 'placeholderShadowing'], [$table, $phShadowId]);
1265 // Hold auto-versionized ids of placeholders:
1266 $this->autoVersionIdMap
[$table][$this->substNEWwithIDs
[$id]] = $phShadowId;
1269 $this->insertDB($table, $id, $fieldArray, false, $incomingFieldArray['uid']);
1272 if ($table === 'pages') {
1273 // only a certain number of fields needs to be checked for updates
1274 // if $this->checkSimilar is TRUE, fields with unchanged values are already removed here
1275 $fieldsToCheck = array_intersect($this->pagetreeRefreshFieldsFromPages
, array_keys($fieldArray));
1276 if (!empty($fieldsToCheck)) {
1277 $this->pagetreeNeedsRefresh
= true;
1280 $this->updateDB($table, $id, $fieldArray);
1281 $this->placeholderShadowing($table, $id);
1284 // Hook: processDatamap_afterDatabaseOperations
1285 // Note: When using the hook after INSERT operations, you will only get the temporary NEW... id passed to your hook as $id,
1286 // but you can easily translate it to the real uid of the inserted record using the $this->substNEWwithIDs array.
1287 $this->hook_processDatamap_afterDatabaseOperations($hookObjectsArr, $status, $table, $id, $fieldArray);
1290 // Process the stack of relations to remap/correct
1291 $this->processRemapStack();
1292 $this->dbAnalysisStoreExec();
1293 $this->removeRegisteredFiles();
1294 // Hook: processDatamap_afterAllOperations
1295 // Note: When this hook gets called, all operations on the submitted data have been finished.
1296 foreach ($hookObjectsArr as $hookObj) {
1297 if (method_exists($hookObj, 'processDatamap_afterAllOperations')) {
1298 $hookObj->processDatamap_afterAllOperations($this);
1301 if ($this->isOuterMostInstance()) {
1302 $this->processClearCacheQueue();
1303 $this->resetElementsToBeDeleted();
1308 * @param string $table
1309 * @param string $row
1310 * @param string $key
1314 protected function normalizeTimeFormat(string $table, string $value, string $dbType): string
1316 $connection = GeneralUtility
::makeInstance(ConnectionPool
::class)->getConnectionForTable($table);
1317 $platform = $connection->getDatabasePlatform();
1318 if ($platform instanceof SQLServerPlatform
) {
1319 $defaultLength = QueryHelper
::getDateTimeFormats()[$dbType]['empty'];
1323 strlen($defaultLength)
1330 * Sets the "sorting" DB field and the "pid" field of an incoming record that should be added (NEW1234)
1331 * depending on the record that should be added or where it should be added.
1333 * This method is called from process_datamap()
1335 * @param string $table the table name of the record to insert
1336 * @param int $pid the real PID (numeric) where the record should be
1337 * @param array $fieldArray field+value pairs to add
1338 * @return array the modified field array
1340 protected function resolveSortingAndPidForNewRecord(string $table, int $pid, array $fieldArray): array
1342 $sortColumn = $GLOBALS['TCA'][$table]['ctrl']['sortby'] ??
'';
1343 // Points to a page on which to insert the element, possibly in the top of the page
1345 // Ensure that the "pid" is not a translated page ID, but the default page ID
1346 $pid = $this->getDefaultLanguagePageId($pid);
1347 // The numerical pid is inserted in the data array
1348 $fieldArray['pid'] = $pid;
1349 // If this table is sorted we better find the top sorting number
1351 $fieldArray[$sortColumn] = $this->getSortNumber($table, 0, $pid);
1353 } elseif ($sortColumn) {
1354 // Points to another record before itself
1355 // If this table is sorted we better find the top sorting number
1356 // Because $pid is < 0, getSortNumber() returns an array
1357 $sortingInfo = $this->getSortNumber($table, 0, $pid);
1358 $fieldArray['pid'] = $sortingInfo['pid'];
1359 $fieldArray[$sortColumn] = $sortingInfo['sortNumber'];
1361 // Here we fetch the PID of the record that we point to
1362 $record = $this->recordInfo($table, abs($pid), 'pid');
1363 // Ensure that the "pid" is not a translated page ID, but the default page ID
1364 $fieldArray['pid'] = $this->getDefaultLanguagePageId($record['pid']);
1370 * Fix shadowing of data in case we are editing an offline version of a live "New" placeholder record:
1372 * @param string $table Table name
1373 * @param int $id Record uid
1375 public function placeholderShadowing($table, $id)
1377 if ($liveRec = BackendUtility
::getLiveVersionOfRecord($table, $id, '*')) {
1378 if (VersionState
::cast($liveRec['t3ver_state'])->indicatesPlaceholder()) {
1379 $justStoredRecord = BackendUtility
::getRecord($table, $id);
1381 $shadowCols = $GLOBALS['TCA'][$table]['ctrl']['shadowColumnsForNewPlaceholders'];
1382 $shadowCols .= ',' . $GLOBALS['TCA'][$table]['ctrl']['languageField'];
1383 $shadowCols .= ',' . $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
1384 if (isset($GLOBALS['TCA'][$table]['ctrl']['translationSource'])) {
1385 $shadowCols .= ',' . $GLOBALS['TCA'][$table]['ctrl']['translationSource'];
1387 $shadowCols .= ',' . $GLOBALS['TCA'][$table]['ctrl']['type'];
1388 $shadowCols .= ',' . $GLOBALS['TCA'][$table]['ctrl']['label'];
1389 $shadowColumns = array_unique(GeneralUtility
::trimExplode(',', $shadowCols, true));
1390 foreach ($shadowColumns as $fieldName) {
1391 if ((string)$justStoredRecord[$fieldName] !== (string)$liveRec[$fieldName] && isset($GLOBALS['TCA'][$table]['columns'][$fieldName]) && $fieldName !== 'uid' && $fieldName !== 'pid') {
1392 $newRecord[$fieldName] = $justStoredRecord[$fieldName];
1395 if (!empty($newRecord)) {
1396 if ($this->enableLogging
) {
1397 $this->log($table, $liveRec['uid'], 0, 0, 0, 'Shadowing done on fields <i>' . implode(',', array_keys($newRecord)) . '</i> in placeholder record ' . $table . ':' . $liveRec['uid'] . ' (offline version UID=' . $id . ')', -1, [], $this->eventPid($table, $liveRec['uid'], $liveRec['pid']));
1399 $this->updateDB($table, $liveRec['uid'], $newRecord);
1406 * Create a placeholder title for the label field that does match the field requirements
1408 * @param string $table The table name
1409 * @param string $placeholderContent Placeholder content to be used
1410 * @return string placeholder value
1412 public function getPlaceholderTitleForTableLabel($table, $placeholderContent = null)
1414 if ($placeholderContent === null) {
1415 $placeholderContent = 'PLACEHOLDER';
1418 $labelPlaceholder = '[' . $placeholderContent . ', WS#' . $this->BE_USER
->workspace
. ']';
1419 $labelField = $GLOBALS['TCA'][$table]['ctrl']['label'];
1420 if (!isset($GLOBALS['TCA'][$table]['columns'][$labelField]['config']['eval'])) {
1421 return $labelPlaceholder;
1423 $evalCodesArray = GeneralUtility
::trimExplode(',', $GLOBALS['TCA'][$table]['columns'][$labelField]['config']['eval'], true);
1424 $transformedLabel = $this->checkValue_input_Eval($labelPlaceholder, $evalCodesArray, '', $table);
1425 return $transformedLabel['value'] ??
$labelPlaceholder;
1429 * Filling in the field array
1430 * $this->excludedTablesAndFields is used to filter fields if needed.
1432 * @param string $table Table name
1433 * @param int $id Record ID
1434 * @param array $fieldArray Default values, Preset $fieldArray with 'pid' maybe (pid and uid will be not be overridden anyway)
1435 * @param array $incomingFieldArray Is which fields/values you want to set. There are processed and put into $fieldArray if OK
1436 * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted.
1437 * @param string $status Is 'new' or 'update'
1438 * @param int $tscPID TSconfig PID
1439 * @return array Field Array
1441 public function fillInFieldArray($table, $id, $fieldArray, $incomingFieldArray, $realPid, $status, $tscPID)
1444 $originalLanguageRecord = null;
1445 $originalLanguage_diffStorage = null;
1446 $diffStorageFlag = false;
1447 // Setting 'currentRecord' and 'checkValueRecord':
1448 if (strpos($id, 'NEW') !== false) {
1449 // Must have the 'current' array - not the values after processing below...
1450 $checkValueRecord = $fieldArray;
1451 // IF $incomingFieldArray is an array, overlay it.
1452 // The point is that when new records are created as copies with flex type fields there might be a field containing information about which DataStructure to use and without that information the flexforms cannot be correctly processed.... This should be OK since the $checkValueRecord is used by the flexform evaluation only anyways...
1453 if (is_array($incomingFieldArray) && is_array($checkValueRecord)) {
1454 ArrayUtility
::mergeRecursiveWithOverrule($checkValueRecord, $incomingFieldArray);
1456 $currentRecord = $checkValueRecord;
1458 // We must use the current values as basis for this!
1459 $currentRecord = ($checkValueRecord = $this->recordInfo($table, $id, '*'));
1460 // This is done to make the pid positive for offline versions; Necessary to have diff-view for page translations in workspaces.
1461 BackendUtility
::fixVersioningPid($table, $currentRecord);
1464 // Get original language record if available:
1465 if (is_array($currentRecord)
1466 && $GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']
1467 && $GLOBALS['TCA'][$table]['ctrl']['languageField']
1468 && $currentRecord[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0
1469 && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']
1470 && (int)$currentRecord[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] > 0
1472 $originalLanguageRecord = $this->recordInfo($table, $currentRecord[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']], '*');
1473 BackendUtility
::workspaceOL($table, $originalLanguageRecord);
1474 $originalLanguage_diffStorage = unserialize($currentRecord[$GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']]);
1477 $this->checkValue_currentRecord
= $checkValueRecord;
1478 // In the following all incoming value-fields are tested:
1479 // - Are the user allowed to change the field?
1480 // - Is the field uid/pid (which are already set)
1481 // - perms-fields for pages-table, then do special things...
1482 // - If the field is nothing of the above and the field is configured in TCA, the fieldvalues are evaluated by ->checkValue
1483 // If everything is OK, the field is entered into $fieldArray[]
1484 foreach ($incomingFieldArray as $field => $fieldValue) {
1485 if (isset($this->excludedTablesAndFields
[$table . '-' . $field]) ||
$this->data_disableFields
[$table][$id][$field]) {
1489 // The field must be editable.
1490 // Checking if a value for language can be changed:
1491 $languageDeny = $GLOBALS['TCA'][$table]['ctrl']['languageField'] && (string)$GLOBALS['TCA'][$table]['ctrl']['languageField'] === (string)$field && !$this->BE_USER
->checkLanguageAccess($fieldValue);
1492 if ($languageDeny) {
1499 // Nothing happens, already set
1501 case 'perms_userid':
1502 case 'perms_groupid':
1505 case 'perms_everybody':
1506 // Permissions can be edited by the owner or the administrator
1507 if ($table === 'pages' && ($this->admin ||
$status === 'new' ||
$this->pageInfo($id, 'perms_userid') == $this->userid
)) {
1508 $value = (int)$fieldValue;
1510 case 'perms_userid':
1511 case 'perms_groupid':
1512 $fieldArray[$field] = $value;
1515 if ($value >= 0 && $value < (2 ** 5)) {
1516 $fieldArray[$field] = $value;
1527 case 't3ver_tstamp':
1528 // t3ver_label is not here because it CAN be edited as a regular field!
1531 $fieldArray[$field] = $fieldValue;
1534 if (isset($GLOBALS['TCA'][$table]['columns'][$field])) {
1535 // Evaluating the value
1536 $res = $this->checkValue($table, $field, $fieldValue, $id, $status, $realPid, $tscPID);
1537 if (array_key_exists('value', $res)) {
1538 $fieldArray[$field] = $res['value'];
1540 // Add the value of the original record to the diff-storage content:
1541 if ($GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']) {
1542 $originalLanguage_diffStorage[$field] = $this->updateModeL10NdiffDataClear ?
'' : $originalLanguageRecord[$field];
1543 $diffStorageFlag = true;
1545 // If autoversioning is happening we need to perform a nasty hack. The case is parallel to a similar hack inside checkValue_group_select_file().
1546 // When a copy or version is made of a record, a search is made for any RTEmagic* images in fields having the "images" soft reference parser applied.
1547 // That should be TRUE for RTE fields. If any are found they are duplicated to new names and the file reference in the bodytext is updated accordingly.
1548 // However, with auto-versioning the submitted content of the field will just overwrite the corrected values. This leaves a) lost RTEmagic files and b) creates a double reference to the old files.
1549 // The only solution I can come up with is detecting when auto versioning happens, then see if any RTEmagic images was copied and if so make a stupid string-replace of the content !
1550 if ($this->autoVersioningUpdate
=== true) {
1551 if (is_array($this->RTEmagic_copyIndex
[$table][$id][$field])) {
1552 foreach ($this->RTEmagic_copyIndex
[$table][$id][$field] as $oldRTEmagicName => $newRTEmagicName) {
1553 $fieldArray[$field] = str_replace(' src="' . $oldRTEmagicName . '"', ' src="' . $newRTEmagicName . '"', $fieldArray[$field]);
1557 } elseif ($GLOBALS['TCA'][$table]['ctrl']['origUid'] === $field) {
1558 // Allow value for original UID to pass by...
1559 $fieldArray[$field] = $fieldValue;
1564 // Dealing with a page translation, setting "sorting", "pid", "perms_*" to the same values as the original record
1565 if ($table === 'pages' && is_array($originalLanguageRecord)) {
1566 $fieldArray['sorting'] = $originalLanguageRecord['sorting'];
1567 $fieldArray['perms_userid'] = $originalLanguageRecord['perms_userid'];
1568 $fieldArray['perms_groupid'] = $originalLanguageRecord['perms_groupid'];
1569 $fieldArray['perms_user'] = $originalLanguageRecord['perms_user'];
1570 $fieldArray['perms_group'] = $originalLanguageRecord['perms_group'];
1571 $fieldArray['perms_everybody'] = $originalLanguageRecord['perms_everybody'];
1574 // Add diff-storage information:
1575 if ($diffStorageFlag
1576 && !array_key_exists($GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField'], $fieldArray)
1578 // If the field is set it would probably be because of an undo-operation - in which case we should not update the field of course...
1579 $fieldArray[$GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']] = serialize($originalLanguage_diffStorage);
1581 // Return fieldArray
1585 /*********************************************
1587 * Evaluation of input values
1589 ********************************************/
1591 * Evaluates a value according to $table/$field settings.
1592 * This function is for real database fields - NOT FlexForm "pseudo" fields.
1593 * NOTICE: Calling this function expects this: 1) That the data is saved! (files are copied and so on) 2) That files registered for deletion IS deleted at the end (with ->removeRegisteredFiles() )
1595 * @param string $table Table name
1596 * @param string $field Field name
1597 * @param string $value Value to be evaluated. Notice, this is the INPUT value from the form. The original value (from any existing record) must be manually looked up inside the function if needed - or taken from $currentRecord array.
1598 * @param string $id The record-uid, mainly - but not exclusively - used for logging
1599 * @param string $status 'update' or 'new' flag
1600 * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted. If $realPid is -1 it means that a new version of the record is being inserted.
1601 * @param int $tscPID TSconfig PID
1602 * @return array Returns the evaluated $value as key "value" in this array. Can be checked with isset($res['value']) ...
1604 public function checkValue($table, $field, $value, $id, $status, $realPid, $tscPID)
1609 // Processing special case of field pages.doktype
1610 if ($table === 'pages' && $field === 'doktype') {
1611 // If the user may not use this specific doktype, we issue a warning
1612 if (!($this->admin || GeneralUtility
::inList($this->BE_USER
->groupData
['pagetypes_select'], $value))) {
1613 if ($this->enableLogging
) {
1614 $propArr = $this->getRecordProperties($table, $id);
1615 $this->log($table, $id, 5, 0, 1, 'You cannot change the \'doktype\' of page \'%s\' to the desired value.', 1, [$propArr['header']], $propArr['event_pid']);
1619 if ($status === 'update') {
1620 // This checks 1) if we should check for disallowed tables and 2) if there are records from disallowed tables on the current page
1621 $onlyAllowedTables = $GLOBALS['PAGES_TYPES'][$value]['onlyAllowedTables'] ??
$GLOBALS['PAGES_TYPES']['default']['onlyAllowedTables'];
1622 if ($onlyAllowedTables) {
1623 // use the real page id (default language)
1624 $recordId = $this->getDefaultLanguagePageId($id);
1625 $theWrongTables = $this->doesPageHaveUnallowedTables($recordId, $value);
1626 if ($theWrongTables) {
1627 if ($this->enableLogging
) {
1628 $propArr = $this->getRecordProperties($table, $id);
1629 $this->log($table, $id, 5, 0, 1, '\'doktype\' of page \'%s\' could not be changed because the page contains records from disallowed tables; %s', 2, [$propArr['header'], $theWrongTables], $propArr['event_pid']);
1638 if ((int)$id !== 0) {
1639 // Get current value:
1640 $curValueRec = $this->recordInfo($table, $id, $field);
1641 // isset() won't work here, since values can be NULL
1642 if ($curValueRec !== null && array_key_exists($field, $curValueRec)) {
1643 $curValue = $curValueRec[$field];
1647 // Getting config for the field
1648 $tcaFieldConf = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
1650 // Create $recFID only for those types that need it
1652 $tcaFieldConf['type'] === 'flex'
1653 ||
$tcaFieldConf['type'] === 'group' && ($tcaFieldConf['internal_type'] === 'file' ||
$tcaFieldConf['internal_type'] === 'file_reference')
1655 $recFID = $table . ':' . $id . ':' . $field;
1660 // Perform processing:
1661 $res = $this->checkValue_SW($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $realPid, $recFID, $field, $this->uploadedFileArray
[$table][$id][$field], $tscPID);
1666 * Branches out evaluation of a field value based on its type as configured in $GLOBALS['TCA']
1667 * Can be called for FlexForm pseudo fields as well, BUT must not have $field set if so.
1669 * @param array $res The result array. The processed value (if any!) is set in the "value" key.
1670 * @param string $value The value to set.
1671 * @param array $tcaFieldConf Field configuration from $GLOBALS['TCA']
1672 * @param string $table Table name
1673 * @param int $id UID of record
1674 * @param mixed $curValue Current value of the field
1675 * @param string $status 'update' or 'new' flag
1676 * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted. If $realPid is -1 it means that a new version of the record is being inserted.
1677 * @param string $recFID Field identifier [table:uid:field] for flexforms
1678 * @param string $field Field name. Must NOT be set if the call is for a flexform field (since flexforms are not allowed within flexforms).
1679 * @param array $uploadedFiles
1680 * @param int $tscPID TSconfig PID
1681 * @param array $additionalData Additional data to be forwarded to sub-processors
1682 * @return array Returns the evaluated $value as key "value" in this array.
1684 public function checkValue_SW($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $realPid, $recFID, $field, $uploadedFiles, $tscPID, array $additionalData = null)
1686 // Convert to NULL value if defined in TCA
1687 if ($value === null && !empty($tcaFieldConf['eval']) && GeneralUtility
::inList($tcaFieldConf['eval'], 'null')) {
1688 $res = ['value' => null];
1692 switch ($tcaFieldConf['type']) {
1694 $res = $this->checkValueForText($value, $tcaFieldConf, $table, $id, $realPid, $field);
1697 case 'imageManipulation':
1699 $res['value'] = $value;
1702 $res = $this->checkValueForInput($value, $tcaFieldConf, $table, $id, $realPid, $field);
1705 $res = $this->checkValueForCheck($res, $value, $tcaFieldConf, $table, $id, $realPid, $field);
1708 $res = $this->checkValueForRadio($res, $value, $tcaFieldConf, $table, $id, $realPid, $field);
1712 $res = $this->checkValueForGroupSelect($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $recFID, $uploadedFiles, $field);
1715 $res = $this->checkValueForInline($res, $value, $tcaFieldConf, $table, $id, $status, $field, $additionalData);
1718 // FlexForms are only allowed for real fields.
1720 $res = $this->checkValueForFlex($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $realPid, $recFID, $tscPID, $uploadedFiles, $field);
1726 $res = $this->checkValueForInternalReferences($res, $value, $tcaFieldConf, $table, $id, $field);
1731 * Checks values that are used for internal references. If the provided $value
1732 * is a NEW-identifier, the direct processing is stopped. Instead, the value is
1733 * forwarded to the remap-stack to be post-processed and resolved into a proper
1734 * UID after all data has been resolved.
1736 * This method considers TCA types that cannot handle and resolve these internal
1737 * values directly, like 'passthrough', 'none' or 'user'. Values are only modified
1738 * here if the $field is used as 'transOrigPointerField' or 'translationSource'.
1740 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
1741 * @param string $value The value to set.
1742 * @param array $tcaFieldConf Field configuration from TCA
1743 * @param string $table Table name
1744 * @param int $id UID of record
1745 * @param string $field The field name
1746 * @return array The result array. The processed value (if any!) is set in the "value" key.
1748 protected function checkValueForInternalReferences(array $res, $value, $tcaFieldConf, $table, $id, $field)
1750 $relevantFieldNames = [
1751 $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] ??
null,
1752 $GLOBALS['TCA'][$table]['ctrl']['translationSource'] ??
null,
1756 // in case field is empty
1758 // in case the field is not relevant
1759 ||
!in_array($field, $relevantFieldNames)
1760 // in case the 'value' index has been unset already
1761 ||
!array_key_exists('value', $res)
1762 // in case it's not a NEW-identifier
1763 ||
strpos($value, 'NEW') === false
1768 $valueArray = [$value];
1769 $this->remapStackRecords
[$table][$id] = ['remapStackIndex' => count($this->remapStack
)];
1770 $this->addNewValuesToRemapStackChildIds($valueArray);
1771 $this->remapStack
[] = [
1772 'args' => [$valueArray, $tcaFieldConf, $id, $table, $field],
1773 'pos' => ['valueArray' => 0, 'tcaFieldConf' => 1, 'id' => 2, 'table' => 3],
1776 unset($res['value']);
1782 * Evaluate "text" type values.
1784 * @param string $value The value to set.
1785 * @param array $tcaFieldConf Field configuration from TCA
1786 * @param string $table Table name
1787 * @param int $id UID of record
1788 * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted. If $realPid is -1 it means that a new version of the record is being inserted.
1789 * @param string $field Field name
1790 * @return array $res The result array. The processed value (if any!) is set in the "value" key.
1792 protected function checkValueForText($value, $tcaFieldConf, $table, $id, $realPid, $field)
1794 if (isset($tcaFieldConf['eval']) && $tcaFieldConf['eval'] !== '') {
1795 $cacheId = $this->getFieldEvalCacheIdentifier($tcaFieldConf['eval']);
1796 $evalCodesArray = $this->runtimeCache
->get($cacheId);
1797 if (!is_array($evalCodesArray)) {
1798 $evalCodesArray = GeneralUtility
::trimExplode(',', $tcaFieldConf['eval'], true);
1799 $this->runtimeCache
->set($cacheId, $evalCodesArray);
1801 $valueArray = $this->checkValue_text_Eval($value, $evalCodesArray, $tcaFieldConf['is_in']);
1803 $valueArray = ['value' => $value];
1806 // Handle richtext transformations
1807 if ($this->dontProcessTransformations
) {
1810 $recordType = BackendUtility
::getTCAtypeValue($table, $this->checkValue_currentRecord
);
1811 $columnsOverridesConfigOfField = $GLOBALS['TCA'][$table]['types'][$recordType]['columnsOverrides'][$field]['config'] ??
null;
1812 if ($columnsOverridesConfigOfField) {
1813 ArrayUtility
::mergeRecursiveWithOverrule($tcaFieldConf, $columnsOverridesConfigOfField);
1815 if (isset($tcaFieldConf['enableRichtext']) && (bool)$tcaFieldConf['enableRichtext'] === true) {
1816 $richtextConfigurationProvider = GeneralUtility
::makeInstance(Richtext
::class);
1817 $richtextConfiguration = $richtextConfigurationProvider->getConfiguration($table, $field, $realPid, $recordType, $tcaFieldConf);
1818 $parseHTML = GeneralUtility
::makeInstance(RteHtmlParser
::class);
1819 $parseHTML->init($table . ':' . $field, $realPid);
1820 $valueArray['value'] = $parseHTML->RTE_transform($value, [], 'db', $richtextConfiguration);
1827 * Evaluate "input" type values.
1829 * @param string $value The value to set.
1830 * @param array $tcaFieldConf Field configuration from TCA
1831 * @param string $table Table name
1832 * @param int $id UID of record
1833 * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted. If $realPid is -1 it means that a new version of the record is being inserted.
1834 * @param string $field Field name
1835 * @return array $res The result array. The processed value (if any!) is set in the "value" key.
1837 protected function checkValueForInput($value, $tcaFieldConf, $table, $id, $realPid, $field)
1839 // Handle native date/time fields
1840 $isDateOrDateTimeField = false;
1843 $dateTimeTypes = QueryHelper
::getDateTimeTypes();
1844 // normal integer "date" fields (timestamps) are handled in checkValue_input_Eval
1845 if (isset($tcaFieldConf['dbType']) && in_array($tcaFieldConf['dbType'], $dateTimeTypes, true)) {
1846 if (empty($value)) {
1849 $isDateOrDateTimeField = true;
1850 $dateTimeFormats = QueryHelper
::getDateTimeFormats();
1851 $format = $dateTimeFormats[$tcaFieldConf['dbType']]['format'];
1853 // Convert the date/time into a timestamp for the sake of the checks
1854 $emptyValue = $dateTimeFormats[$tcaFieldConf['dbType']]['empty'];
1855 // We store UTC timestamps in the database, which is what getTimestamp() returns.
1856 $dateTime = new \
DateTime($value);
1857 $value = $value === $emptyValue ?
null : $dateTime->getTimestamp();
1860 // Secures the string-length to be less than max.
1861 if ((int)$tcaFieldConf['max'] > 0) {
1862 $value = mb_substr((string)$value, 0, (int)$tcaFieldConf['max'], 'utf-8');
1865 if (empty($tcaFieldConf['eval'])) {
1866 $res = ['value' => $value];
1868 // Process evaluation settings:
1869 $cacheId = $this->getFieldEvalCacheIdentifier($tcaFieldConf['eval']);
1870 $evalCodesArray = $this->runtimeCache
->get($cacheId);
1871 if (!is_array($evalCodesArray)) {
1872 $evalCodesArray = GeneralUtility
::trimExplode(',', $tcaFieldConf['eval'], true);
1873 $this->runtimeCache
->set($cacheId, $evalCodesArray);
1876 $res = $this->checkValue_input_Eval($value, $evalCodesArray, $tcaFieldConf['is_in'], $table);
1877 if (isset($tcaFieldConf['dbType']) && isset($res['value']) && !$res['value']) {
1878 // set the value to null if we have an empty value for a native field
1879 $res['value'] = null;
1882 // Process UNIQUE settings:
1883 // Field is NOT set for flexForms - which also means that uniqueInPid and unique is NOT available for flexForm fields! Also getUnique should not be done for versioning and if PID is -1 ($realPid<0) then versioning is happening...
1884 if ($field && $realPid >= 0 && !empty($res['value'])) {
1885 if (in_array('uniqueInPid', $evalCodesArray, true)) {
1886 $res['value'] = $this->getUnique($table, $field, $res['value'], $id, $realPid);
1888 if ($res['value'] && in_array('unique', $evalCodesArray, true)) {
1889 $res['value'] = $this->getUnique($table, $field, $res['value'], $id);
1894 // Checking range of value:
1895 // @todo: The "checkbox" option was removed for type=input, this check could be probably relaxed?
1896 if ($tcaFieldConf['range'] && $res['value'] != $tcaFieldConf['checkbox'] && (int)$res['value'] !== (int)$tcaFieldConf['default']) {
1897 if (isset($tcaFieldConf['range']['upper']) && (int)$res['value'] > (int)$tcaFieldConf['range']['upper']) {
1898 $res['value'] = (int)$tcaFieldConf['range']['upper'];
1900 if (isset($tcaFieldConf['range']['lower']) && (int)$res['value'] < (int)$tcaFieldConf['range']['lower']) {
1901 $res['value'] = (int)$tcaFieldConf['range']['lower'];
1905 // Handle native date/time fields
1906 if ($isDateOrDateTimeField) {
1907 // Convert the timestamp back to a date/time
1908 $res['value'] = $res['value'] ?
gmdate($format, $res['value']) : $emptyValue;
1914 * Evaluates 'check' type values.
1916 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
1917 * @param string $value The value to set.
1918 * @param array $tcaFieldConf Field configuration from TCA
1919 * @param string $table Table name
1920 * @param int $id UID of record
1921 * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted. If $realPid is -1 it means that a new version of the record is being inserted.
1922 * @param string $field Field name
1923 * @return array Modified $res array
1925 protected function checkValueForCheck($res, $value, $tcaFieldConf, $table, $id, $realPid, $field)
1927 $items = $tcaFieldConf['items'];
1928 if ($tcaFieldConf['itemsProcFunc']) {
1929 /** @var ItemProcessingService $processingService */
1930 $processingService = GeneralUtility
::makeInstance(ItemProcessingService
::class);
1931 $items = $processingService->getProcessingItems(
1935 $this->checkValue_currentRecord
,
1937 $tcaFieldConf['items']
1942 if ($items !== null) {
1943 $itemC = count($items);
1948 $maxV = (2 ** $itemC) - 1;
1950 // @todo: throw LogicException here? Negative values for checkbox items do not make sense and indicate a coding error.
1953 if ($value > $maxV) {
1954 // @todo: This case is pretty ugly: If there is an itemsProcFunc registered, and if it returns a dynamic,
1955 // @todo: changing list of items, then it may happen that a value is transformed and vanished checkboxes
1956 // @todo: are permanently removed from the value.
1957 // @todo: Suggestion: Throw an exception instead? Maybe a specific, catchable exception that generates a
1958 // @todo: error message to the user - dynamic item sets via itemProcFunc on check would be a bad idea anyway.
1959 $value = $value & $maxV;
1961 if ($field && $realPid >= 0 && $value > 0 && !empty($tcaFieldConf['eval'])) {
1962 $evalCodesArray = GeneralUtility
::trimExplode(',', $tcaFieldConf['eval'], true);
1963 $otherRecordsWithSameValue = [];
1964 $maxCheckedRecords = 0;
1965 if (in_array('maximumRecordsCheckedInPid', $evalCodesArray, true)) {
1966 $otherRecordsWithSameValue = $this->getRecordsWithSameValue($table, $id, $field, $value, $realPid);
1967 $maxCheckedRecords = (int)$tcaFieldConf['validation']['maximumRecordsCheckedInPid'];
1969 if (in_array('maximumRecordsChecked', $evalCodesArray, true)) {
1970 $otherRecordsWithSameValue = $this->getRecordsWithSameValue($table, $id, $field, $value);
1971 $maxCheckedRecords = (int)$tcaFieldConf['validation']['maximumRecordsChecked'];
1974 // there are more than enough records with value "1" in the DB
1975 // if so, set this value to "0" again
1976 if ($maxCheckedRecords && count($otherRecordsWithSameValue) >= $maxCheckedRecords) {
1978 $this->log($table, $id, 5, 0, 1, 'Could not activate checkbox for field "%s". A total of %s record(s) can have this checkbox activated. Uncheck other records first in order to activate the checkbox of this record.', -1, [$this->getLanguageService()->sL(BackendUtility
::getItemLabel($table, $field)), $maxCheckedRecords]);
1981 $res['value'] = $value;
1986 * Evaluates 'radio' type values.
1988 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
1989 * @param string $value The value to set.
1990 * @param array $tcaFieldConf Field configuration from TCA
1991 * @param string $table The table of the record
1992 * @param int $id The id of the record
1993 * @param int $pid The pid of the record
1994 * @param string $field The field to check
1995 * @return array Modified $res array
1997 protected function checkValueForRadio($res, $value, $tcaFieldConf, $table, $id, $pid, $field)
1999 if (is_array($tcaFieldConf['items'])) {
2000 foreach ($tcaFieldConf['items'] as $set) {
2001 if ((string)$set[1] === (string)$value) {
2002 $res['value'] = $value;
2008 // if no value was found and an itemsProcFunc is defined, check that for the value
2009 if ($tcaFieldConf['itemsProcFunc'] && empty($res['value'])) {
2010 $processingService = GeneralUtility
::makeInstance(ItemProcessingService
::class);
2011 $processedItems = $processingService->getProcessingItems(
2015 $this->checkValue_currentRecord
,
2017 $tcaFieldConf['items']
2020 foreach ($processedItems as $set) {
2021 if ((string)$set[1] === (string)$value) {
2022 $res['value'] = $value;
2032 * Evaluates 'group' or 'select' type values.
2034 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
2035 * @param string|array $value The value to set.
2036 * @param array $tcaFieldConf Field configuration from TCA
2037 * @param string $table Table name
2038 * @param int $id UID of record
2039 * @param mixed $curValue Current value of the field
2040 * @param string $status 'update' or 'new' flag
2041 * @param string $recFID Field identifier [table:uid:field] for flexforms
2042 * @param array $uploadedFiles
2043 * @param string $field Field name
2044 * @return array Modified $res array
2046 protected function checkValueForGroupSelect($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $recFID, $uploadedFiles, $field)
2048 // Detecting if value sent is an array and if so, implode it around a comma:
2049 if (is_array($value)) {
2050 $value = implode(',', $value);
2052 // This converts all occurrences of '{' to the byte 123 in the string - this is needed in very rare cases where file names with special characters (e.g. ???, umlaut) gets sent to the server as HTML entities instead of bytes. The error is done only by MSIE, not Mozilla and Opera.
2053 // Anyway, this should NOT disturb anything else:
2054 $value = $this->convNumEntityToByteValue($value);
2055 // When values are sent as group or select they come as comma-separated values which are exploded by this function:
2056 $valueArray = $this->checkValue_group_select_explodeSelectGroupValue($value);
2057 // If multiple is not set, remove duplicates:
2058 if (!$tcaFieldConf['multiple']) {
2059 $valueArray = array_unique($valueArray);
2061 // If an exclusive key is found, discard all others:
2062 if ($tcaFieldConf['type'] === 'select' && $tcaFieldConf['exclusiveKeys']) {
2063 $exclusiveKeys = GeneralUtility
::trimExplode(',', $tcaFieldConf['exclusiveKeys']);
2064 foreach ($valueArray as $index => $key) {
2065 if (in_array($key, $exclusiveKeys, true)) {
2066 $valueArray = [$index => $key];
2071 // This could be a good spot for parsing the array through a validation-function which checks if the values are correct (except that database references are not in their final form - but that is the point, isn't it?)
2072 // NOTE!!! Must check max-items of files before the later check because that check would just leave out file names if there are too many!!
2073 $valueArray = $this->applyFiltersToValues($tcaFieldConf, $valueArray);
2074 // Checking for select / authMode, removing elements from $valueArray if any of them is not allowed!
2075 if ($tcaFieldConf['type'] === 'select' && $tcaFieldConf['authMode']) {
2076 $preCount = count($valueArray);
2077 foreach ($valueArray as $index => $key) {
2078 if (!$this->BE_USER
->checkAuthMode($table, $field, $key, $tcaFieldConf['authMode'])) {
2079 unset($valueArray[$index]);
2082 // During the check it turns out that the value / all values were removed - we respond by simply returning an empty array so nothing is written to DB for this field.
2083 if ($preCount && empty($valueArray)) {
2088 if ($tcaFieldConf['type'] === 'group'
2089 && in_array($tcaFieldConf['internal_type'], ['file', 'file_reference'], true)) {
2090 $valueArray = $this->checkValue_group_select_file($valueArray, $tcaFieldConf, $curValue, $uploadedFiles, $status, $table, $id, $recFID);
2092 // For select types which has a foreign table attached:
2093 $unsetResult = false;
2095 $tcaFieldConf['type'] === 'group' && $tcaFieldConf['internal_type'] === 'db'
2096 ||
$tcaFieldConf['type'] === 'select' && ($tcaFieldConf['foreign_table'] ||
isset($tcaFieldConf['special']) && $tcaFieldConf['special'] === 'languages')
2098 // check, if there is a NEW... id in the value, that should be substituted later
2099 if (strpos($value, 'NEW') !== false) {
2100 $this->remapStackRecords
[$table][$id] = ['remapStackIndex' => count($this->remapStack
)];
2101 $this->addNewValuesToRemapStackChildIds($valueArray);
2102 $this->remapStack
[] = [
2103 'func' => 'checkValue_group_select_processDBdata',
2104 'args' => [$valueArray, $tcaFieldConf, $id, $status, $tcaFieldConf['type'], $table, $field],
2105 'pos' => ['valueArray' => 0, 'tcaFieldConf' => 1, 'id' => 2, 'table' => 5],
2108 $unsetResult = true;
2110 $valueArray = $this->checkValue_group_select_processDBdata($valueArray, $tcaFieldConf, $id, $status, $tcaFieldConf['type'], $table, $field);
2113 if (!$unsetResult) {
2114 $newVal = $this->checkValue_checkMax($tcaFieldConf, $valueArray);
2115 $res['value'] = $this->castReferenceValue(implode(',', $newVal), $tcaFieldConf);
2117 unset($res['value']);
2123 * Applies the filter methods from a column's TCA configuration to a value array.
2125 * @param array $tcaFieldConfiguration
2126 * @param array $values
2127 * @return array|mixed
2128 * @throws \RuntimeException
2130 protected function applyFiltersToValues(array $tcaFieldConfiguration, array $values)
2132 if (empty($tcaFieldConfiguration['filter']) ||
!is_array($tcaFieldConfiguration['filter'])) {
2135 foreach ($tcaFieldConfiguration['filter'] as $filter) {
2136 if (empty($filter['userFunc'])) {
2139 $parameters = $filter['parameters'] ?
: [];
2140 $parameters['values'] = $values;
2141 $parameters['tcaFieldConfig'] = $tcaFieldConfiguration;
2142 $values = GeneralUtility
::callUserFunction($filter['userFunc'], $parameters, $this);
2143 if (!is_array($values)) {
2144 throw new \
RuntimeException('Failed calling filter userFunc.', 1336051942);
2151 * Handling files for group/select function
2153 * @param array $valueArray Array of incoming file references. Keys are numeric, values are files (basically, this is the exploded list of incoming files)
2154 * @param array $tcaFieldConf Configuration array from TCA of the field
2155 * @param string $curValue Current value of the field
2156 * @param array $uploadedFileArray Array of uploaded files, if any
2157 * @param string $status 'update' or 'new' flag
2158 * @param string $table tablename of record
2159 * @param int $id UID of record
2160 * @param string $recFID Field identifier [table:uid:field] for flexforms
2161 * @return array Modified value array
2163 * @throws \RuntimeException
2165 public function checkValue_group_select_file($valueArray, $tcaFieldConf, $curValue, $uploadedFileArray, $status, $table, $id, $recFID)
2167 // If file handling should NOT be bypassed, do processing:
2168 if (!$this->bypassFileHandling
) {
2169 // If any files are uploaded, add them to value array
2170 // Numeric index means that there are multiple files
2171 if (isset($uploadedFileArray[0])) {
2172 $uploadedFiles = $uploadedFileArray;
2174 // There is only one file
2175 $uploadedFiles = [$uploadedFileArray];
2177 foreach ($uploadedFiles as $uploadedFileArray) {
2178 if (!empty($uploadedFileArray['name']) && $uploadedFileArray['tmp_name'] !== 'none') {
2179 $valueArray[] = $uploadedFileArray['tmp_name'];
2180 $this->alternativeFileName
[$uploadedFileArray['tmp_name']] = $uploadedFileArray['name'];
2183 // Creating fileFunc object.
2184 if (!$this->fileFunc
) {
2185 $this->fileFunc
= GeneralUtility
::makeInstance(BasicFileUtility
::class);
2187 // Setting permitted extensions.
2188 $this->fileFunc
->setFileExtensionPermissions($tcaFieldConf['allowed'], $tcaFieldConf['disallowed'] ?
: '*');
2190 // If there is an upload folder defined:
2191 if ($tcaFieldConf['uploadfolder'] && $tcaFieldConf['internal_type'] === 'file') {
2192 $currentFilesForHistory = null;
2193 // If filehandling should NOT be bypassed, do processing:
2194 if (!$this->bypassFileHandling
) {
2196 $propArr = $this->getRecordProperties($table, $id);
2197 // Get destination path:
2198 $dest = Environment
::getPublicPath() . '/' . $tcaFieldConf['uploadfolder'];
2199 // If we are updating:
2200 if ($status === 'update') {
2201 // Traverse the input values and convert to absolute filenames in case the update happens to an autoVersionized record.
2202 // Background: This is a horrible workaround! The problem is that when a record is auto-versionized the files of the record get copied and therefore get new names which is overridden with the names from the original record in the incoming data meaning both lost files and double-references!
2203 // The only solution I could come up with (except removing support for managing files when autoversioning) was to convert all relative files to absolute names so they are copied again (and existing files deleted). This should keep references intact but means that some files are copied, then deleted after being copied _again_.
2204 // Actually, the same problem applies to database references in case auto-versioning would include sub-records since in such a case references are remapped - and they would be overridden due to the same principle then.
2205 // Illustration of the problem comes here:
2206 // We have a record 123 with a file logo.gif. We open and edit the files header in a workspace. So a new version is automatically made.
2207 // The versions uid is 456 and the file is copied to "logo_01.gif". But the form data that we sent was based on uid 123 and hence contains the filename "logo.gif" from the original.
2208 // The file management code below will do two things: First it will blindly accept "logo.gif" as a file attached to the record (thus creating a double reference) and secondly it will find that "logo_01.gif" was not in the incoming filelist and therefore should be deleted.
2209 // If we prefix the incoming file "logo.gif" with its absolute path it will be seen as a new file added. Thus it will be copied to "logo_02.gif". "logo_01.gif" will still be deleted but since the files are the same the difference is zero - only more processing and file copying for no reason. But it will work.
2210 if ($this->autoVersioningUpdate
=== true) {
2211 foreach ($valueArray as $key => $theFile) {
2212 // If it is an already attached file...
2213 if ($theFile === PathUtility
::basename($theFile)) {
2214 $valueArray[$key] = Environment
::getPublicPath() . '/' . $tcaFieldConf['uploadfolder'] . '/' . $theFile;
2218 // Finding the CURRENT files listed, either from MM or from the current record.
2219 $theFileValues = [];
2220 // If MM relations for the files also!
2221 if ($tcaFieldConf['MM']) {
2222 $dbAnalysis = $this->createRelationHandlerInstance();
2223 /** @var $dbAnalysis RelationHandler */
2224 $dbAnalysis->start('', 'files', $tcaFieldConf['MM'], $id);
2225 foreach ($dbAnalysis->itemArray
as $item) {
2227 $theFileValues[] = $item['id'];
2231 $theFileValues = GeneralUtility
::trimExplode(',', $curValue, true);
2233 $currentFilesForHistory = implode(',', $theFileValues);
2234 // DELETE files: If existing files were found, traverse those and register files for deletion which has been removed:
2235 if (!empty($theFileValues)) {
2236 // Traverse the input values and for all input values which match an EXISTING value, remove the existing from $theFileValues array (this will result in an array of all the existing files which should be deleted!)
2237 foreach ($valueArray as $key => $theFile) {
2238 if ($theFile && strpos(GeneralUtility
::fixWindowsFilePath($theFile), '/') === false) {
2239 $theFileValues = ArrayUtility
::removeArrayEntryByValue($theFileValues, $theFile);
2242 // This array contains the filenames in the uploadfolder that should be deleted:
2243 foreach ($theFileValues as $key => $theFile) {
2244 $theFile = trim($theFile);
2245 if (@is_file
($dest . '/' . $theFile)) {
2246 $this->removeFilesStore
[] = $dest . '/' . $theFile;
2247 } elseif ($theFile) {
2248 $this->log($table, $id, 5, 0, 1, 'Could not delete file \'%s\' (does not exist). (%s)', 10, [$dest . '/' . $theFile, $recFID], $propArr['event_pid']);
2253 // Traverse the submitted values:
2254 foreach ($valueArray as $key => $theFile) {
2256 $maxSize = (int)$tcaFieldConf['max_size'];
2257 // Must be cleared. Else a faulty fileref may be inserted if the below code returns an error!
2259 // a FAL file was added, now resolve the file object and get the absolute path
2260 // @todo in future versions this needs to be modified to handle FAL objects natively
2261 if (!empty($theFile) && MathUtility
::canBeInterpretedAsInteger($theFile)) {
2262 $fileObject = ResourceFactory
::getInstance()->getFileObject($theFile);
2263 $theFile = $fileObject->getForLocalProcessing(false);
2265 // NEW FILES? If the value contains '/' it indicates, that the file
2266 // is new and should be added to the uploadsdir (whether its absolute or relative does not matter here)
2267 if (strpos(GeneralUtility
::fixWindowsFilePath($theFile), '/') !== false) {
2268 // Check various things before copying file:
2269 // File and destination must exist
2270 if (@is_dir
($dest) && (@is_file
($theFile) || @is_uploaded_file
($theFile))) {
2272 if (is_uploaded_file($theFile) && $theFile == $uploadedFileArray['tmp_name']) {
2273 $fileSize = $uploadedFileArray['size'];
2275 $fileSize = filesize($theFile);
2278 if (!$maxSize ||
$fileSize <= $maxSize * 1024) {
2279 // Prepare filename:
2280 $theEndFileName = $this->alternativeFileName
[$theFile] ??
$theFile;
2281 $fI = GeneralUtility
::split_fileref($theEndFileName);
2282 // Check for allowed extension:
2283 if ($this->fileFunc
->checkIfAllowed($fI['fileext'], $dest, $theEndFileName)) {
2284 $theDestFile = $this->fileFunc
->getUniqueName($this->fileFunc
->cleanFileName($fI['file']), $dest);
2285 // If we have a unique destination filename, then write the file:
2287 GeneralUtility
::upload_copy_move($theFile, $theDestFile);
2288 // Hook for post-processing the upload action
2289 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processUpload'] ??
[] as $className) {
2290 $hookObject = GeneralUtility
::makeInstance($className);
2291 if (!$hookObject instanceof DataHandlerProcessUploadHookInterface
) {
2292 throw new \
UnexpectedValueException($className . ' must implement interface ' . DataHandlerProcessUploadHookInterface
::class, 1279962349);
2294 $hookObject->processUpload_postProcessAction($theDestFile, $this);
2296 $this->copiedFileMap
[$theFile] = $theDestFile;
2298 if (!@is_file
($theDestFile)) {
2299 $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)', 16, [$theFile, PathUtility
::dirname($theDestFile), $recFID], $propArr['event_pid']);
2302 $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: No destination file (%s) possible!. (%s)', 11, [$theFile, $theDestFile, $recFID], $propArr['event_pid']);
2305 $this->log($table, $id, 5, 0, 1, 'File extension \'%s\' not allowed. (%s)', 12, [$fI['fileext'], $recFID], $propArr['event_pid']);
2308 $this->log($table, $id, 5, 0, 1, 'Filesize (%s) of file \'%s\' exceeds limit (%s). (%s)', 13, [GeneralUtility
::formatSize($fileSize), $theFile, GeneralUtility
::formatSize($maxSize * 1024), $recFID], $propArr['event_pid']);
2311 $this->log($table, $id, 5, 0, 1, 'The destination (%s) or the source file (%s) does not exist. (%s)', 14, [$dest, $theFile, $recFID], $propArr['event_pid']);
2313 // If the destination file was created, we will set the new filename in the value array, otherwise unset the entry in the value array!
2314 if (@is_file
($theDestFile)) {
2315 $info = GeneralUtility
::split_fileref($theDestFile);
2316 // The value is set to the new filename
2317 $valueArray[$key] = $info['file'];
2319 // The value is set to the new filename
2320 unset($valueArray[$key]);
2325 // If MM relations for the files, we will set the relations as MM records and change the valuearray to contain a single entry with a count of the number of files!
2326 if ($tcaFieldConf['MM']) {
2327 /** @var $dbAnalysis RelationHandler */
2328 $dbAnalysis = $this->createRelationHandlerInstance();
2330 $dbAnalysis->tableArray
['files'] = [];
2331 foreach ($valueArray as $key => $theFile) {
2333 $dbAnalysis->itemArray
[]['id'] = $theFile;
2335 if ($status === 'update') {
2336 $dbAnalysis->writeMM($tcaFieldConf['MM'], $id, 0);
2337 $newFiles = implode(',', $dbAnalysis->getValueArray());
2338 list(, , $recFieldName) = explode(':', $recFID);
2339 if ($currentFilesForHistory != $newFiles) {
2340 $this->mmHistoryRecords
[$table . ':' . $id]['oldRecord'][$recFieldName] = $currentFilesForHistory;
2341 $this->mmHistoryRecords
[$table . ':' . $id]['newRecord'][$recFieldName] = $newFiles;
2343 $this->mmHistoryRecords
[$table . ':' . $id]['oldRecord'][$recFieldName] = '';
2344 $this->mmHistoryRecords
[$table . ':' . $id]['newRecord'][$recFieldName] = '';
2347 $this->dbAnalysisStore
[] = [$dbAnalysis, $tcaFieldConf['MM'], $id, 0];
2349 $valueArray = $dbAnalysis->countItems();
2352 if (!empty($valueArray)) {
2353 // If filehandling should NOT be bypassed, do processing:
2354 if (!$this->bypassFileHandling
) {
2356 $propArr = $this->getRecordProperties($table, $id);
2357 foreach ($valueArray as &$theFile) {
2358 // FAL handling: it's a UID, thus it is resolved to the absolute path
2359 if (!empty($theFile) && MathUtility
::canBeInterpretedAsInteger($theFile)) {
2360 $fileObject = ResourceFactory
::getInstance()->getFileObject($theFile);
2361 $theFile = $fileObject->getForLocalProcessing(false);
2363 if ($this->alternativeFilePath
[$theFile]) {
2364 // If alternative File Path is set for the file, then it was an import
2365 // don't import the file if it already exists
2366 if (@is_file
(Environment
::getPublicPath() . '/' . $this->alternativeFilePath
[$theFile])) {
2367 $theFile = Environment
::getPublicPath() . '/' . $this->alternativeFilePath
[$theFile];
2368 } elseif (@is_file
($theFile)) {
2369 $dest = PathUtility
::dirname(Environment
::getPublicPath() . '/' . $this->alternativeFilePath
[$theFile]);
2370 if (!@is_dir
($dest)) {
2371 GeneralUtility
::mkdir_deep($dest);
2374 $maxSize = (int)$tcaFieldConf['max_size'];
2375 // Must be cleared. Else a faulty fileref may be inserted if the below code returns an error!
2377 $fileSize = filesize($theFile);
2379 if (!$maxSize ||
$fileSize <= $maxSize * 1024) {
2380 // Prepare filename:
2381 $theEndFileName = $this->alternativeFileName
[$theFile] ??
$theFile;
2382 $fI = GeneralUtility
::split_fileref($theEndFileName);
2383 // Check for allowed extension:
2384 if ($this->fileFunc
->checkIfAllowed($fI['fileext'], $dest, $theEndFileName)) {
2385 $theDestFile = Environment
::getPublicPath() . '/' . $this->alternativeFilePath
[$theFile];
2388 GeneralUtility
::upload_copy_move($theFile, $theDestFile);
2389 $this->copiedFileMap
[$theFile] = $theDestFile;
2391 if (!@is_file
($theDestFile)) {
2392 $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)', 16, [$theFile, PathUtility
::dirname($theDestFile), $recFID], $propArr['event_pid']);
2395 $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: No destination file (%s) possible!. (%s)', 11, [$theFile, $theDestFile, $recFID], $propArr['event_pid']);
2398 $this->log($table, $id, 5, 0, 1, 'File extension \'%s\' not allowed. (%s)', 12, [$fI['fileext'], $recFID], $propArr['event_pid']);
2401 $this->log($table, $id, 5, 0, 1, 'Filesize (%s) of file \'%s\' exceeds limit (%s). (%s)', 13, [GeneralUtility
::formatSize($fileSize), $theFile, GeneralUtility
::formatSize($maxSize * 1024), $recFID], $propArr['event_pid']);
2403 // If the destination file was created, we will set the new filename in the value array, otherwise unset the entry in the value array!
2404 if (@is_file
($theDestFile)) {
2405 // The value is set to the new filename
2406 $theFile = $theDestFile;
2408 // The value is set to the new filename
2413 if (!empty($theFile)) {
2414 $theFile = GeneralUtility
::fixWindowsFilePath($theFile);
2415 if (GeneralUtility
::isFirstPartOfStr($theFile, Environment
::getPublicPath())) {
2416 $theFile = PathUtility
::stripPathSitePrefix($theFile);
2428 * Evaluates 'flex' type values.
2430 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
2431 * @param string|array $value The value to set.
2432 * @param array $tcaFieldConf Field configuration from TCA
2433 * @param string $table Table name
2434 * @param int $id UID of record
2435 * @param mixed $curValue Current value of the field
2436 * @param string $status 'update' or 'new' flag
2437 * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted. If $realPid is -1 it means that a new version of the record is being inserted.
2438 * @param string $recFID Field identifier [table:uid:field] for flexforms
2439 * @param int $tscPID TSconfig PID
2440 * @param array $uploadedFiles Uploaded files for the field
2441 * @param string $field Field name
2442 * @return array Modified $res array
2444 protected function checkValueForFlex($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $realPid, $recFID, $tscPID, $uploadedFiles, $field)
2446 if (is_array($value)) {
2447 // This value is necessary for flex form processing to happen on flexform fields in page records when they are copied.
2448 // Problem: when copying a page, flexform XML comes along in the array for the new record - but since $this->checkValue_currentRecord
2449 // does not have a uid or pid for that sake, the FlexFormTools->getDataStructureIdentifier() function returns no good DS. For new
2450 // records we do know the expected PID so therefore we send that with this special parameter. Only active when larger than zero.
2451 $row = $this->checkValue_currentRecord
;
2452 if ($status === 'new') {
2453 $row['pid'] = $realPid;
2456 $flexFormTools = GeneralUtility
::makeInstance(FlexFormTools
::class);
2458 // Get data structure. The methods may throw various exceptions, with some of them being
2459 // ok in certain scenarios, for instance on new record rows. Those are ok to "eat" here
2460 // and substitute with a dummy DS.
2461 $dataStructureArray = ['sheets' => ['sDEF' => []]];
2463 $dataStructureIdentifier = $flexFormTools->getDataStructureIdentifier(
2464 ['config' => $tcaFieldConf],
2470 $dataStructureArray = $flexFormTools->parseDataStructureByIdentifier($dataStructureIdentifier);
2471 } catch (InvalidParentRowException
$e) {
2472 } catch (InvalidParentRowLoopException
$e) {
2473 } catch (InvalidParentRowRootException
$e) {
2474 } catch (InvalidPointerFieldValueException
$e) {
2475 } catch (InvalidIdentifierException
$e) {
2478 // Get current value array:
2479 $currentValueArray = (string)$curValue !== '' ? GeneralUtility
::xml2array($curValue) : [];
2480 if (!is_array($currentValueArray)) {
2481 $currentValueArray = [];
2483 // Remove all old meta for languages...
2484 // Evaluation of input values:
2485 $value['data'] = $this->checkValue_flex_procInData($value['data'], $currentValueArray['data'], $uploadedFiles['data'], $dataStructureArray, [$table, $id, $curValue, $status, $realPid, $recFID, $tscPID]);
2486 // Create XML from input value:
2487 $xmlValue = $this->checkValue_flexArray2Xml($value, true);
2489 // Here we convert the currently submitted values BACK to an array, then merge the two and then BACK to XML again. This is needed to ensure the charsets are the same
2490 // (provided that the current value was already stored IN the charset that the new value is converted to).
2491 $arrValue = GeneralUtility
::xml2array($xmlValue);
2493 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkFlexFormValue'] ??
[] as $className) {
2494 $hookObject = GeneralUtility
::makeInstance($className);
2495 if (method_exists($hookObject, 'checkFlexFormValue_beforeMerge')) {
2496 $hookObject->checkFlexFormValue_beforeMerge($this, $currentValueArray, $arrValue);
2500 ArrayUtility
::mergeRecursiveWithOverrule($currentValueArray, $arrValue);
2501 $xmlValue = $this->checkValue_flexArray2Xml($currentValueArray, true);
2503 // Action commands (sorting order and removals of elements) for flexform sections,
2504 // see FormEngine for the use of this GP parameter
2505 $actionCMDs = GeneralUtility
::_GP('_ACTION_FLEX_FORMdata');
2506 if (is_array($actionCMDs[$table][$id][$field]['data'])) {
2507 $arrValue = GeneralUtility
::xml2array($xmlValue);
2508 $this->_ACTION_FLEX_FORMdata($arrValue['data'], $actionCMDs[$table][$id][$field]['data']);
2509 $xmlValue = $this->checkValue_flexArray2Xml($arrValue, true);
2511 // Create the value XML:
2513 $res['value'] .= $xmlValue;
2516 $res['value'] = $value;
2523 * Converts an array to FlexForm XML
2525 * @param array $array Array with FlexForm data
2526 * @param bool $addPrologue If set, the XML prologue is returned as well.
2527 * @return string Input array converted to XML
2529 public function checkValue_flexArray2Xml($array, $addPrologue = false)
2531 /** @var $flexObj FlexFormTools */
2532 $flexObj = GeneralUtility
::makeInstance(FlexFormTools
::class);
2533 return $flexObj->flexArray2Xml($array, $addPrologue);
2537 * Actions for flex form element (move, delete)
2538 * allows to remove and move flexform sections
2540 * @param array $valueArray by reference
2541 * @param array $actionCMDs
2543 protected function _ACTION_FLEX_FORMdata(&$valueArray, $actionCMDs)
2545 if (!is_array($valueArray) ||
!is_array($actionCMDs)) {
2549 foreach ($actionCMDs as $key => $value) {
2550 if ($key === '_ACTION') {
2551 // First, check if there are "commands":
2552 if (current($actionCMDs[$key]) === '') {
2556 asort($actionCMDs[$key]);
2557 $newValueArray = [];
2558 foreach ($actionCMDs[$key] as $idx => $order) {
2559 // Just one reflection here: It is clear that when removing elements from a flexform, then we will get lost
2560 // files unless we act on this delete operation by traversing and deleting files that were referred to.
2561 if ($order !== 'DELETE') {
2562 $newValueArray[$idx] = $valueArray[$idx];
2564 unset($valueArray[$idx]);
2566 $valueArray +
= $newValueArray;
2567 } elseif (is_array($actionCMDs[$key]) && isset($valueArray[$key])) {
2568 $this->_ACTION_FLEX_FORMdata($valueArray[$key], $actionCMDs[$key]);
2574 * Evaluates 'inline' type values.
2575 * (partly copied from the select_group function on this issue)
2577 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
2578 * @param string $value The value to set.
2579 * @param array $tcaFieldConf Field configuration from TCA
2580 * @param array $PP Additional parameters in a numeric array: $table,$id,$curValue,$status,$realPid,$recFID
2581 * @param string $field Field name
2582 * @param array $additionalData Additional data to be forwarded to sub-processors
2583 * @return array Modified $res array
2585 public function checkValue_inline($res, $value, $tcaFieldConf, $PP, $field, array $additionalData = null)
2587 list($table, $id, , $status) = $PP;
2588 $this->checkValueForInline($res, $value, $tcaFieldConf, $table, $id, $status, $field, $additionalData);
2592 * Evaluates 'inline' type values.
2593 * (partly copied from the select_group function on this issue)
2595 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
2596 * @param string $value The value to set.
2597 * @param array $tcaFieldConf Field configuration from TCA
2598 * @param string $table Table name
2599 * @param int $id UID of record
2600 * @param string $status 'update' or 'new' flag
2601 * @param string $field Field name
2602 * @param array $additionalData Additional data to be forwarded to sub-processors
2603 * @return array|bool Modified $res array
2605 public function checkValueForInline($res, $value, $tcaFieldConf, $table, $id, $status, $field, array $additionalData = null)
2607 if (!$tcaFieldConf['foreign_table']) {
2608 // Fatal error, inline fields should always have a foreign_table defined
2611 // When values are sent they come as comma-separated values which are exploded by this function:
2612 $valueArray = GeneralUtility
::trimExplode(',', $value);
2613 // Remove duplicates: (should not be needed)
2614 $valueArray = array_unique($valueArray);
2615 // Example for received data:
2616 // $value = 45,NEW4555fdf59d154,12,123
2617 // We need to decide whether we use the stack or can save the relation directly.
2618 if (!empty($value) && (strpos($value, 'NEW') !== false ||
!MathUtility
::canBeInterpretedAsInteger($id))) {
2619 $this->remapStackRecords
[$table][$id] = ['remapStackIndex' => count($this->remapStack
)];
2620 $this->addNewValuesToRemapStackChildIds($valueArray);
2621 $this->remapStack
[] = [
2622 'func' => 'checkValue_inline_processDBdata',
2623 'args' => [$valueArray, $tcaFieldConf, $id, $status, $table, $field, $additionalData],
2624 'pos' => ['valueArray' => 0, 'tcaFieldConf' => 1, 'id' => 2, 'table' => 4],
2625 'additionalData' => $additionalData,
2628 unset($res['value']);
2629 } elseif ($value || MathUtility
::canBeInterpretedAsInteger($id)) {
2630 $res['value'] = $this->checkValue_inline_processDBdata($valueArray, $tcaFieldConf, $id, $status, $table, $field, $additionalData);
2636 * Checks if a fields has more items than defined via TCA in maxitems.
2637 * If there are more items than allowed, the item list is truncated to the defined number.
2639 * @param array $tcaFieldConf Field configuration from TCA
2640 * @param array $valueArray Current value array of items
2641 * @return array The truncated value array of items
2643 public function checkValue_checkMax($tcaFieldConf, $valueArray)
2645 // BTW, checking for min and max items here does NOT make any sense when MM is used because the above function
2646 // calls will just return an array with a single item (the count) if MM is used... Why didn't I perform the check
2647 // before? Probably because we could not evaluate the validity of record uids etc... Hmm...
2648 // NOTE to the comment: It's not really possible to check for too few items, because you must then determine first,
2649 // if the field is actual used regarding the CType.
2650 $maxitems = isset($tcaFieldConf['maxitems']) ?
(int)$tcaFieldConf['maxitems'] : 99999;
2651 return array_slice($valueArray, 0, $maxitems);
2654 /*********************************************
2656 * Helper functions for evaluation functions.
2658 ********************************************/
2660 * Gets a unique value for $table/$id/$field based on $value
2662 * @param string $table Table name
2663 * @param string $field Field name for which $value must be unique
2664 * @param string $value Value string.
2665 * @param int $id UID to filter out in the lookup (the record itself...)
2666 * @param int $newPid If set, the value will be unique for this PID
2667 * @return string Modified value (if not-unique). Will be the value appended with a number (until 100, then the function just breaks).
2669 public function getUnique($table, $field, $value, $id, $newPid = 0)
2671 // If the field is configured in TCA, proceed:
2672 if (is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['columns'][$field])) {
2674 $statement = $this->getUniqueCountStatement($newValue, $table, $field, (int)$id, (int)$newPid);
2675 // For as long as records with the test-value existing, try again (with incremented numbers appended)
2676 if ($statement->fetchColumn()) {
2677 for ($counter = 0; $counter <= 100; $counter++
) {
2678 $newValue = $value . $counter;
2679 $statement->bindValue(1, $newValue);
2680 $statement->execute();
2681 if (!$statement->fetchColumn()) {
2692 * Gets the count of records for a unique field
2694 * @param string $value The string value which should be unique
2695 * @param string $table Table name
2696 * @param string $field Field name for which $value must be unique
2697 * @param int $uid UID to filter out in the lookup (the record itself...)
2698 * @param int $pid If set, the value will be unique for this PID
2699 * @return \Doctrine\DBAL\Driver\Statement|int Return the prepared statement to check uniqueness
2701 protected function getUniqueCountStatement(
2708 $queryBuilder = GeneralUtility
::makeInstance(ConnectionPool
::class)->getQueryBuilderForTable($table);
2709 $this->addDeleteRestriction($queryBuilder->getRestrictions()->removeAll());
2714 $queryBuilder->expr()->eq($field, $queryBuilder->createPositionalParameter($value, \PDO
::PARAM_STR
)),
2715 $queryBuilder->expr()->neq('uid', $queryBuilder->createPositionalParameter($uid, \PDO
::PARAM_INT
))
2718 $queryBuilder->andWhere(
2719 $queryBuilder->expr()->eq('pid', $queryBuilder->createPositionalParameter($pid, \PDO
::PARAM_INT
))
2722 // pid>=0 for versioning
2723 $queryBuilder->andWhere(
2724 $queryBuilder->expr()->gte('pid', $queryBuilder->createPositionalParameter(0, \PDO
::PARAM_INT
))
2728 return $queryBuilder->execute();
2732 * gets all records that have the same value in a field
2733 * excluding the given uid
2735 * @param string $tableName Table name
2736 * @param int $uid UID to filter out in the lookup (the record itself...)
2737 * @param string $fieldName Field name for which $value must be unique
2738 * @param string $value Value string.
2739 * @param int $pageId If set, the value will be unique for this PID
2742 public function getRecordsWithSameValue($tableName, $uid, $fieldName, $value, $pageId = 0)
2745 if (empty($GLOBALS['TCA'][$tableName]['columns'][$fieldName])) {
2750 $pageId = (int)$pageId;
2752 $queryBuilder = GeneralUtility
::makeInstance(ConnectionPool
::class)->getQueryBuilderForTable($tableName);
2753 $queryBuilder->getRestrictions()
2755 ->add(GeneralUtility
::makeInstance(DeletedRestriction
::class))
2756 ->add(GeneralUtility
::makeInstance(BackendWorkspaceRestriction
::class));
2758 $queryBuilder->select('*')
2761 $queryBuilder->expr()->eq(
2763 $queryBuilder->createNamedParameter($value, \PDO
::PARAM_STR
)
2765 $queryBuilder->expr()->neq(
2767 $queryBuilder->createNamedParameter($uid, \PDO
::PARAM_INT
)
2772 $queryBuilder->andWhere(
2773 $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageId, \PDO
::PARAM_INT
))
2776 $queryBuilder->andWhere(
2777 $queryBuilder->expr()->gte('pid', $queryBuilder->createNamedParameter(0, \PDO
::PARAM_INT
))
2781 $result = $queryBuilder->execute()->fetchAll();
2787 * @param string $value The field value to be evaluated
2788 * @param array $evalArray Array of evaluations to traverse.
2789 * @param string $is_in The "is_in" value of the field configuration from TCA
2792 public function checkValue_text_Eval($value, $evalArray, $is_in)
2796 foreach ($evalArray as $func) {
2799 $value = trim($value);
2807 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
2808 if (class_exists($func)) {
2809 $evalObj = GeneralUtility
::makeInstance($func);
2810 if (method_exists($evalObj, 'evaluateFieldValue')) {
2811 $value = $evalObj->evaluateFieldValue($value, $is_in, $set);
2818 $res['value'] = $value;
2824 * Evaluation of 'input'-type values based on 'eval' list
2826 * @param string $value Value to evaluate
2827 * @param array $evalArray Array of evaluations to traverse.
2828 * @param string $is_in Is-in string for 'is_in' evaluation
2829 * @param string $table Table name the eval is evaluated on
2830 * @return array Modified $value in key 'value' or empty array
2832 public function checkValue_input_Eval($value, $evalArray, $is_in, string $table = ''): array
2836 foreach ($evalArray as $func) {
2840 $value = (int)$value;
2844 // If $value is a pure integer we have the number of seconds, we can store that directly
2845 if ($value !== '' && !MathUtility
::canBeInterpretedAsInteger($value)) {
2846 // $value is an ISO 8601 date
2847 $value = (new \
DateTime($value))->getTimestamp();
2852 // If $value is a pure integer we have the number of seconds, we can store that directly
2853 if ($value !== null && $value !== '' && !MathUtility
::canBeInterpretedAsInteger($value)) {
2854 // The value we receive from JS is an ISO 8601 date, which is always in UTC. (the JS code works like that, on purpose!)
2855 // For instance "1999-11-11T11:11:11Z"
2856 // Since the user actually specifies the time in the server's local time, we need to mangle this
2857 // to reflect the server TZ. So we make this 1999-11-11T11:11:11+0200 (assuming Europe/Vienna here)
2858 // In the database we store the date in UTC (1999-11-11T09:11:11Z), hence we take the timestamp of this converted value.
2859 // For achieving this we work with timestamps only (which are UTC) and simply adjust it for the
2862 // Make the date from JS a timestamp
2863 $value = (new \
DateTime($value))->getTimestamp();
2864 } catch (\Exception
$e) {
2865 // set the default timezone value to achieve the value of 0 as a result
2866 $value = (int)date('Z', 0);
2869 // @todo this hacky part is problematic when it comes to times around DST switch! Add test to prove that this is broken.
2870 $value -= date('Z', $value);
2874 $value = preg_replace('/[^0-9,\\.-]/', '', $value);
2875 $negative = $value[0] === '-';
2876 $value = strtr($value, [',' => '.', '-' => '']);
2877 if (strpos($value, '.') === false) {
2880 $valueArray = explode('.', $value);
2881 $dec = array_pop($valueArray);
2882 $value = implode('', $valueArray) . '.' . $dec;
2886 $value = number_format($value, 2, '.', '');
2889 if (strlen($value) !== 32) {
2894 $value = trim($value);
2897 $value = mb_strtoupper($value, 'utf-8');
2900 $value = mb_strtolower($value, 'utf-8');
2903 if (!isset($value) ||
$value === '') {
2908 $c = mb_strlen($value);