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 TYPO3\CMS\Backend\Utility\BackendUtility
;
18 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication
;
19 use TYPO3\CMS\Core\Cache\CacheManager
;
20 use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
;
21 use TYPO3\CMS\Core\Charset\CharsetConverter
;
22 use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools
;
23 use TYPO3\CMS\Core\Database\DatabaseConnection
;
24 use TYPO3\CMS\Core\Database\ReferenceIndex
;
25 use TYPO3\CMS\Core\Database\RelationHandler
;
26 use TYPO3\CMS\Core\Html\RteHtmlParser
;
27 use TYPO3\CMS\Core\Messaging\FlashMessage
;
28 use TYPO3\CMS\Core\Messaging\FlashMessageService
;
29 use TYPO3\CMS\Core\
Resource\ResourceFactory
;
30 use TYPO3\CMS\Core\Type\Bitmask\Permission
;
31 use TYPO3\CMS\Core\Utility\ArrayUtility
;
32 use TYPO3\CMS\Core\Utility\File\BasicFileUtility
;
33 use TYPO3\CMS\Core\Utility\GeneralUtility
;
34 use TYPO3\CMS\Core\Utility\MathUtility
;
35 use TYPO3\CMS\Core\Utility\PathUtility
;
36 use TYPO3\CMS\Core\Utility\StringUtility
;
37 use TYPO3\CMS\Core\Versioning\VersionState
;
40 * The main data handler class which takes care of correctly updating and inserting records.
41 * This class was formerly known as TCEmain.
43 * This is the TYPO3 Core Engine class for manipulation of the database
44 * This class is used by eg. the tce_db.php script which provides an the interface for POST forms to this class.
47 * - $GLOBALS['TCA'] must exist
48 * - $GLOBALS['LANG'] must exist
50 * tce_db.php for further comments and SYNTAX! Also see document 'TYPO3 Core API' for details.
54 // *********************
55 // Public variables you can configure before using the class:
56 // *********************
58 * If TRUE, the default log-messages will be stored. This should not be necessary if the locallang-file for the
59 * log-display is properly configured. So disabling this will just save some database-space as the default messages are not saved.
63 public $storeLogMessages = true;
66 * If TRUE, actions are logged to sys_log.
70 public $enableLogging = true;
73 * If TRUE, the datamap array is reversed in the order, which is a nice thing if you're creating a whole new
78 public $reverseOrder = false;
81 * If TRUE, only fields which are different from the database values are saved! In fact, if a whole input array
82 * is similar, it's not saved then.
86 public $checkSimilar = true;
89 * This will read the record after having updated or inserted it. If anything is not properly submitted an error
90 * is written to the log. This feature consumes extra time by selecting records
94 public $checkStoredRecords = true;
97 * If set, values '' and 0 will equal each other when the stored records are checked.
101 public $checkStoredRecords_loose = true;
104 * If this is set, then a page is deleted by deleting the whole branch under it (user must have
105 * delete permissions to it all). If not set, then the page is deleted ONLY if it has no branch.
109 public $deleteTree = false;
112 * If set, then the 'hideAtCopy' flag for tables will be ignored.
116 public $neverHideAtCopy = false;
119 * If set, then the TCE class has been instantiated during an import action of a T3D
123 public $isImporting = false;
126 * If set, then transformations are NOT performed on the input.
130 public $dontProcessTransformations = false;
133 * TRUE: (traditional) Updates when record is saved. For flexforms, updates if change is made to the localized value.
134 * FALSE: Will not update anything.
135 * "FORCE_FFUPD" (string): Like TRUE, but will force update to the FlexForm Field
139 public $updateModeL10NdiffData = true;
142 * If TRUE, the translation diff. fields will in fact be reset so that they indicate that all needs to change again!
143 * It's meant as the opposite of declaring the record translated.
147 public $updateModeL10NdiffDataClear = false;
150 * If TRUE, workspace restrictions are bypassed on edit an create actions (process_datamap()).
151 * YOU MUST KNOW what you do if you use this feature!
155 public $bypassWorkspaceRestrictions = false;
158 * If TRUE, file handling of attached files (addition, deletion etc) is bypassed - the value is saved straight away.
159 * YOU MUST KNOW what you are doing with this feature!
163 public $bypassFileHandling = false;
166 * If TRUE, access check, check for deleted etc. for records is bypassed.
167 * YOU MUST KNOW what you are doing if you use this feature!
171 public $bypassAccessCheckForRecords = false;
174 * Comma-separated list. This list of tables decides which tables will be copied. If empty then none will.
175 * If '*' then all will (that the user has permission to of course)
179 public $copyWhichTables = '*';
182 * If 0 then branch is NOT copied.
183 * If 1 then pages on the 1st level is copied.
184 * If 2 then pages on the second level is copied ... and so on
188 public $copyTree = 0;
191 * [table][fields]=value: New records are created with default values and you can set this array on the
192 * form $defaultValues[$table][$field] = $value to override the default values fetched from TCA.
193 * If ->setDefaultsFromUserTS is called UserTSconfig default values will overrule existing values in this array
194 * (thus UserTSconfig overrules externally set defaults which overrules TCA defaults)
198 public $defaultValues = array();
201 * [table][fields]=value: You can set this array on the form $overrideValues[$table][$field] = $value to
202 * override the incoming data. You must set this externally. You must make sure the fields in this array are also
203 * found in the table, because it's not checked. All columns can be set by this array!
207 public $overrideValues = array();
210 * [filename]=alternative_filename: Use this array to force another name onto a file.
211 * Eg. if you set ['/tmp/blablabal'] = 'my_file.txt' and '/tmp/blablabal' is set for a certain file-field,
212 * then 'my_file.txt' will be used as the name instead.
216 public $alternativeFileName = array();
219 * Array [filename]=alternative_filepath: Same as alternativeFileName but with relative path to the file
223 public $alternativeFilePath = array();
226 * If entries are set in this array corresponding to fields for update, they are ignored and thus NOT updated.
227 * You could set this array from a series of checkboxes with value=0 and hidden fields before the checkbox with 1.
228 * Then an empty checkbox will disable the field.
232 public $data_disableFields = array();
235 * Use this array to validate suggested uids for tables by setting [table]:[uid]. This is a dangerous option
236 * since it will force the inserted record to have a certain UID. The value just have to be TRUE, but if you set
237 * it to "DELETE" it will make sure any record with that UID will be deleted first (raw delete).
238 * The option is used for import of T3D files when synchronizing between two mirrored servers.
239 * As a security measure this feature is available only for Admin Users (for now)
243 public $suggestedInsertUids = array();
246 * Object. Call back object for FlexForm traversal. Useful when external classes wants to use the
247 * iteration functions inside DataHandler for traversing a FlexForm structure.
253 // *********************
254 // Internal variables (mapping arrays) which can be used (read-only) from outside
255 // *********************
257 * Contains mapping of auto-versionized records.
261 public $autoVersionIdMap = array();
264 * 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
268 public $substNEWwithIDs = array();
271 * Like $substNEWwithIDs, but where each old "NEW..." id is mapped to the table it was from.
275 public $substNEWwithIDs_table = array();
278 * Holds the tables and there the ids of newly created child records from IRRE
282 public $newRelatedIDs = array();
285 * This array is the sum of all copying operations in this class. May be READ from outside, thus partly public.
289 public $copyMappingArray_merged = array();
292 * A map between input file name and final destination for files being attached to records.
296 public $copiedFileMap = array();
299 * Contains [table][id][field] of fiels where RTEmagic images was copied. Holds old filename as key and new filename as value.
303 public $RTEmagic_copyIndex = array();
306 * Errors are collected in this variable.
310 public $errorLog = array();
313 * Fields from the pages-table for which changes will trigger a pagetree refresh
317 public $pagetreeRefreshFieldsFromPages = array('pid', 'sorting', 'deleted', 'hidden', 'title', 'doktype', 'is_siteroot', 'fe_group', 'nav_hide', 'nav_title', 'module', 'starttime', 'endtime', 'content_from_pid');
320 * Indicates whether the pagetree needs a refresh because of important changes
324 public $pagetreeNeedsRefresh = false;
326 // *********************
327 // Internal Variables, do not touch.
328 // *********************
330 // Variables set in init() function:
333 * The user-object the script uses. If not set from outside, this is set to the current global $BE_USER.
335 * @var BackendUserAuthentication
340 * Will be set to uid of be_user executing this script
347 * Will be set to username of be_user executing this script
354 * Will be set if user is admin
361 * Can be overridden from $GLOBALS['TYPO3_CONF_VARS']
365 public $defaultPermissions = array(
366 'user' => 'show,edit,delete,new,editcontent',
367 'group' => 'show,edit,new,editcontent',
372 * 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.
376 protected $excludedTablesAndFields = array();
379 * Data submitted from the form view, used to control behaviours,
380 * e.g. this is used to activate/deactivate fields and thus store NULL values
384 protected $control = array();
387 * Set with incoming data array
391 public $datamap = array();
394 * Set with incoming cmd array
398 public $cmdmap = array();
401 * List of changed old record ids to new records ids
405 protected $mmHistoryRecords = array();
408 * List of changed old record ids to new records ids
412 protected $historyRecords = array();
420 public $pMap = array(
433 * Integer: The interval between sorting numbers used with tables with a 'sorting' field defined. Min 1
437 public $sortIntervals = 256;
439 // Internal caching arrays
441 * Used by function checkRecordUpdateAccess() to store whether a record is updatable or not.
445 public $recUpdateAccessCache = array();
448 * User by function checkRecordInsertAccess() to store whether a record can be inserted on a page id
452 public $recInsertAccessCache = array();
455 * Caching array for check of whether records are in a webmount
459 public $isRecordInWebMount_Cache = array();
462 * Caching array for page ids in webmounts
466 public $isInWebMount_Cache = array();
469 * Caching for collecting TSconfig for page ids
473 public $cachedTSconfig = array();
476 * Used for caching page records in pageInfo()
480 public $pageCache = array();
483 * Array caching workspace access for BE_USER
487 public $checkWorkspaceCache = array();
491 * For accumulation of MM relations that must be written after new records are created.
495 public $dbAnalysisStore = array();
498 * For accumulation of files which must be deleted after processing of all input content
502 public $removeFilesStore = array();
505 * Uploaded files, set by process_uploads()
509 public $uploadedFileArray = array();
512 * Used for tracking references that might need correction after operations
516 public $registerDBList = array();
519 * Used for tracking references that might need correction in pid field after operations (e.g. IRRE)
523 public $registerDBPids = array();
526 * Used by the copy action to track the ids of new pages so subpages are correctly inserted!
527 * THIS is internally cleared for each executed copy operation! DO NOT USE THIS FROM OUTSIDE!
528 * Read from copyMappingArray_merged instead which is accumulating this information.
530 * NOTE: This is used by some outside scripts (e.g. hooks), as the results in $copyMappingArray_merged
531 * are only available after an action has been completed.
535 public $copyMappingArray = array();
538 * Array used for remapping uids and values at the end of process_datamap
542 public $remapStack = array();
545 * Array used for remapping uids and values at the end of process_datamap
546 * (e.g. $remapStackRecords[<table>][<uid>] = <index in $remapStack>)
550 public $remapStackRecords = array();
553 * Array used for checking whether new children need to be remapped
557 protected $remapStackChildIds = array();
560 * Array used for executing addition actions after remapping happened (set processRemapStack())
564 protected $remapStackActions = array();
567 * Array used for executing post-processing on the reference index
571 protected $remapStackRefIndex = array();
574 * Array used for additional calls to $this->updateRefIndex
578 public $updateRefIndexStack = array();
581 * Tells, that this DataHandler instance was called from \TYPO3\CMS\Impext\ImportExport.
582 * This variable is set by \TYPO3\CMS\Impext\ImportExport
586 public $callFromImpExp = false;
589 * Array for new flexform index mapping
593 public $newIndexMap = array();
597 * basicFileFunctions object
598 * For "singleton" file-manipulation object
600 * @var BasicFileUtility
605 * Set to "currentRecord" during checking of values.
609 public $checkValue_currentRecord = array();
612 * A signal flag used to tell file processing that auto versioning has happened and hence certain action should be applied.
616 public $autoVersioningUpdate = false;
619 * Disable delete clause
623 protected $disableDeleteClause = false;
628 protected $checkModifyAccessListHookObjects;
633 protected $version_remapMMForVersionSwap_reg;
636 * The outer most instance of \TYPO3\CMS\Core\DataHandling\DataHandler:
637 * This object instantiates itself on versioning and localization ...
639 * @var \TYPO3\CMS\Core\DataHandling\DataHandler
641 protected $outerMostInstance = null;
644 * Internal cache for collecting records that should trigger cache clearing
648 protected static $recordsToClearCacheFor = array();
651 * Internal cache for pids of records which were deleted. It's not possible
652 * to retrieve the parent folder/page at a later stage
656 protected static $recordPidsForDeletedRecords = array();
659 * Database layer. Identical to $GLOBALS['TYPO3_DB']
661 * @var DatabaseConnection
663 protected $databaseConnection;
666 * Runtime Cache to store and retrieve data computed for a single request
668 * @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
670 protected $runtimeCache = null;
673 * Prefix for the cache entries of nested element calls since the runtimeCache has a global scope.
677 protected $cachePrefixNestedElementCalls = 'core-datahandler-nestedElementCalls-';
682 public function __construct()
684 $this->databaseConnection
= $GLOBALS['TYPO3_DB'];
685 $this->runtimeCache
= $this->getRuntimeCache();
689 * @param array $control
691 public function setControl(array $control)
693 $this->control
= $control;
698 * For details, see 'TYPO3 Core API' document.
699 * This function does not start the processing of data, but merely initializes the object
701 * @param array $data Data to be modified or inserted in the database
702 * @param array $cmd Commands to copy, move, delete, localize, versionize records.
703 * @param BackendUserAuthentication|NULL $altUserObject An alternative userobject you can set instead of the default, which is $GLOBALS['BE_USER']
706 public function start($data, $cmd, $altUserObject = null)
708 // Initializing BE_USER
709 $this->BE_USER
= is_object($altUserObject) ?
$altUserObject : $GLOBALS['BE_USER'];
710 $this->userid
= $this->BE_USER
->user
['uid'];
711 $this->username
= $this->BE_USER
->user
['username'];
712 $this->admin
= $this->BE_USER
->user
['admin'];
713 if ($this->BE_USER
->uc
['recursiveDelete']) {
714 $this->deleteTree
= 1;
716 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['explicitConfirmationOfTranslation'] && $this->updateModeL10NdiffData
=== true) {
717 $this->updateModeL10NdiffData
= false;
719 // Initializing default permissions for pages
720 $defaultPermissions = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPermissions'];
721 if (isset($defaultPermissions['user'])) {
722 $this->defaultPermissions
['user'] = $defaultPermissions['user'];
724 if (isset($defaultPermissions['group'])) {
725 $this->defaultPermissions
['group'] = $defaultPermissions['group'];
727 if (isset($defaultPermissions['everybody'])) {
728 $this->defaultPermissions
['everybody'] = $defaultPermissions['everybody'];
730 // generates the excludelist, based on TCA/exclude-flag and non_exclude_fields for the user:
732 $this->excludedTablesAndFields
= array_flip($this->getExcludeListArray());
734 // Setting the data and cmd arrays
735 if (is_array($data)) {
737 $this->datamap
= $data;
739 if (is_array($cmd)) {
741 $this->cmdmap
= $cmd;
746 * Function that can mirror input values in datamap-array to other uid numbers.
747 * 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]
749 * @param array $mirror This array has the syntax $mirror[table_name][uid] = [list of uids to copy data-value TO!]
752 public function setMirror($mirror)
754 if (!is_array($mirror)) {
758 foreach ($mirror as $table => $uid_array) {
759 if (!isset($this->datamap
[$table])) {
763 foreach ($uid_array as $id => $uidList) {
764 if (!isset($this->datamap
[$table][$id])) {
768 $theIdsInArray = GeneralUtility
::trimExplode(',', $uidList, true);
769 foreach ($theIdsInArray as $copyToUid) {
770 $this->datamap
[$table][$copyToUid] = $this->datamap
[$table][$id];
777 * Initializes default values coming from User TSconfig
779 * @param array $userTS User TSconfig array
782 public function setDefaultsFromUserTS($userTS)
784 if (!is_array($userTS)) {
788 foreach ($userTS as $k => $v) {
789 $k = substr($k, 0, -1);
790 if (!$k ||
!is_array($v) ||
!isset($GLOBALS['TCA'][$k])) {
794 if (is_array($this->defaultValues
[$k])) {
795 $this->defaultValues
[$k] = array_merge($this->defaultValues
[$k], $v);
797 $this->defaultValues
[$k] = $v;
803 * Processing of uploaded files.
804 * 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.
806 * @param array $postFiles $_FILES array
809 public function process_uploads($postFiles)
811 if (!is_array($postFiles)) {
816 if ($this->BE_USER
->workspace
!== 0 && $this->BE_USER
->workspaceRec
['freeze']) {
817 if ($this->enableLogging
) {
818 $this->newlog('All editing in this workspace has been frozen!', 1);
822 $subA = reset($postFiles);
823 if (is_array($subA)) {
824 if (is_array($subA['name']) && is_array($subA['type']) && is_array($subA['tmp_name']) && is_array($subA['size'])) {
825 // Initialize the uploadedFilesArray:
826 $this->uploadedFileArray
= array();
828 foreach ($subA as $key => $values) {
829 $this->process_uploads_traverseArray($this->uploadedFileArray
, $values, $key);
832 $this->uploadedFileArray
= $subA;
838 * Traverse the upload array if needed to rearrange values.
840 * @param array $outputArr $this->uploadedFileArray passed by reference
841 * @param array $inputArr Input array ($_FILES parts)
842 * @param string $keyToSet The current $_FILES array key to set on the outermost level.
845 * @see process_uploads()
847 public function process_uploads_traverseArray(&$outputArr, $inputArr, $keyToSet)
849 if (is_array($inputArr)) {
850 foreach ($inputArr as $key => $value) {
851 $this->process_uploads_traverseArray($outputArr[$key], $inputArr[$key], $keyToSet);
854 $outputArr[$keyToSet] = $inputArr;
858 /*********************************************
862 *********************************************/
864 * Hook: processDatamap_afterDatabaseOperations
865 * (calls $hookObj->processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $this);)
867 * Note: When using the hook after INSERT operations, you will only get the temporary NEW... id passed to your hook as $id,
868 * but you can easily translate it to the real uid of the inserted record using the $this->substNEWwithIDs array.
870 * @param array $hookObjectsArr (reference) Array with hook objects
871 * @param string $status (reference) Status of the current operation, 'new' or 'update
872 * @param string $table (reference) The table currently processing data for
873 * @param string $id (reference) The record uid currently processing data for, [integer] or [string] (like 'NEW...')
874 * @param array $fieldArray (reference) The field array of a record
877 public function hook_processDatamap_afterDatabaseOperations(&$hookObjectsArr, &$status, &$table, &$id, &$fieldArray)
879 // Process hook directly:
880 if (!isset($this->remapStackRecords
[$table][$id])) {
881 foreach ($hookObjectsArr as $hookObj) {
882 if (method_exists($hookObj, 'processDatamap_afterDatabaseOperations')) {
883 $hookObj->processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $this);
887 $this->remapStackRecords
[$table][$id]['processDatamap_afterDatabaseOperations'] = array(
889 'fieldArray' => $fieldArray,
890 'hookObjectsArr' => $hookObjectsArr
896 * Gets the 'checkModifyAccessList' hook objects.
897 * The first call initializes the accordant objects.
899 * @return array The 'checkModifyAccessList' hook objects (if any)
900 * @throws \UnexpectedValueException
902 protected function getCheckModifyAccessListHookObjects()
904 if (!isset($this->checkModifyAccessListHookObjects
)) {
905 $this->checkModifyAccessListHookObjects
= array();
906 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'])) {
907 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'] as $classData) {
908 $hookObject = GeneralUtility
::getUserObj($classData);
909 if (!$hookObject instanceof DataHandlerCheckModifyAccessListHookInterface
) {
910 throw new \
UnexpectedValueException('$hookObject must implement interface \\TYPO3\\CMS\\Core\\DataHandling\\DataHandlerCheckModifyAccessListHookInterface', 1251892472);
912 $this->checkModifyAccessListHookObjects
[] = $hookObject;
916 return $this->checkModifyAccessListHookObjects
;
919 /*********************************************
923 *********************************************/
925 * Processing the data-array
926 * Call this function to process the data-array set by start()
930 public function process_datamap()
932 $this->controlActiveElements();
934 // Keep versionized(!) relations here locally:
935 $registerDBList = array();
936 $this->registerElementsToBeDeleted();
937 $this->datamap
= $this->unsetElementsToBeDeleted($this->datamap
);
939 if ($this->BE_USER
->workspace
!== 0 && $this->BE_USER
->workspaceRec
['freeze']) {
940 if ($this->enableLogging
) {
941 $this->newlog('All editing in this workspace has been frozen!', 1);
945 // First prepare user defined objects (if any) for hooks which extend this function:
946 $hookObjectsArr = array();
947 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'])) {
948 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'] as $classRef) {
949 $hookObject = GeneralUtility
::getUserObj($classRef);
950 if (method_exists($hookObject, 'processDatamap_beforeStart')) {
951 $hookObject->processDatamap_beforeStart($this);
953 $hookObjectsArr[] = $hookObject;
956 // 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.
957 $orderOfTables = array();
959 if (isset($this->datamap
['pages'])) {
960 $orderOfTables[] = 'pages';
962 $orderOfTables = array_unique(array_merge($orderOfTables, array_keys($this->datamap
)));
963 // Process the tables...
964 foreach ($orderOfTables as $table) {
966 // - table is set in $GLOBALS['TCA'],
967 // - table is NOT readOnly
968 // - the table is set with content in the data-array (if not, there's nothing to process...)
969 // - permissions for tableaccess OK
970 $modifyAccessList = $this->checkModifyAccessList($table);
971 if ($this->enableLogging
&& !$modifyAccessList) {
972 $this->log($table, 0, 2, 0, 1, 'Attempt to modify table \'%s\' without permission', 1, array($table));
974 if (!isset($GLOBALS['TCA'][$table]) ||
$this->tableReadOnly($table) ||
!is_array($this->datamap
[$table]) ||
!$modifyAccessList) {
978 if ($this->reverseOrder
) {
979 $this->datamap
[$table] = array_reverse($this->datamap
[$table], 1);
981 // For each record from the table, do:
982 // $id is the record uid, may be a string if new records...
983 // $incomingFieldArray is the array of fields
984 foreach ($this->datamap
[$table] as $id => $incomingFieldArray) {
985 if (!is_array($incomingFieldArray)) {
990 // Handle native date/time fields
991 $dateTimeFormats = $this->databaseConnection
->getDateTimeFormats($table);
992 foreach ($GLOBALS['TCA'][$table]['columns'] as $column => $config) {
993 if (isset($incomingFieldArray[$column])) {
994 if (isset($config['config']['dbType']) && ($config['config']['dbType'] === 'date' ||
$config['config']['dbType'] === 'datetime')) {
995 $emptyValue = $dateTimeFormats[$config['config']['dbType']]['empty'];
996 $format = $dateTimeFormats[$config['config']['dbType']]['format'];
997 $incomingFieldArray[$column] = $incomingFieldArray[$column] && $incomingFieldArray[$column] !== $emptyValue ?
gmdate($format, $incomingFieldArray[$column]) : $emptyValue;
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'])) {
1021 $pid_value = $incomingFieldArray['pid'];
1022 // Checking and finding numerical pid, it may be a string-reference to another value
1025 if (strstr($pid_value, 'NEW')) {
1026 if ($pid_value[0] === '-') {
1028 $pid_value = substr($pid_value, 1);
1032 // Trying to find the correct numerical value as it should be mapped by earlier processing of another new record.
1033 if (isset($this->substNEWwithIDs
[$pid_value])) {
1034 if ($negFlag === 1) {
1035 $old_pid_value = $this->substNEWwithIDs
[$pid_value];
1037 $pid_value = (int)($negFlag * $this->substNEWwithIDs
[$pid_value]);
1042 $pid_value = (int)$pid_value;
1043 // The $pid_value is now the numerical pid at this point
1045 $sortRow = $GLOBALS['TCA'][$table]['ctrl']['sortby'];
1046 // Points to a page on which to insert the element, possibly in the top of the page
1047 if ($pid_value >= 0) {
1048 // If this table is sorted we better find the top sorting number
1050 $fieldArray[$sortRow] = $this->getSortNumber($table, 0, $pid_value);
1052 // The numerical pid is inserted in the data array
1053 $fieldArray['pid'] = $pid_value;
1055 // points to another record before ifself
1056 // If this table is sorted we better find the top sorting number
1058 // Because $pid_value is < 0, getSortNumber returns an array
1059 $tempArray = $this->getSortNumber($table, 0, $pid_value);
1060 $fieldArray['pid'] = $tempArray['pid'];
1061 $fieldArray[$sortRow] = $tempArray['sortNumber'];
1063 // Here we fetch the PID of the record that we point to...
1064 $tempdata = $this->recordInfo($table, abs($pid_value), 'pid');
1065 $fieldArray['pid'] = $tempdata['pid'];
1070 $theRealPid = $fieldArray['pid'];
1071 // Now, check if we may insert records on this pid.
1072 if ($theRealPid >= 0) {
1073 // Checks if records can be inserted on this $pid.
1074 $recordAccess = $this->checkRecordInsertAccess($table, $theRealPid);
1075 if ($recordAccess) {
1076 $this->addDefaultPermittedLanguageIfNotSet($table, $incomingFieldArray);
1077 $recordAccess = $this->BE_USER
->recordEditAccessInternals($table, $incomingFieldArray, true);
1078 if (!$recordAccess) {
1079 if ($this->enableLogging
) {
1080 $this->newlog('recordEditAccessInternals() check failed. [' . $this->BE_USER
->errorMsg
. ']', 1);
1082 } elseif (!$this->bypassWorkspaceRestrictions
) {
1083 // Workspace related processing:
1084 // If LIVE records cannot be created in the current PID due to workspace restrictions, prepare creation of placeholder-record
1085 if ($res = $this->BE_USER
->workspaceAllowLiveRecordsInPID($theRealPid, $table)) {
1087 $recordAccess = false;
1088 if ($this->enableLogging
) {
1089 $this->newlog('Stage for versioning root point and users access level did not allow for editing', 1);
1093 // So, if no live records were allowed, we have to create a new version of this record:
1094 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
1095 $createNewVersion = true;
1097 $recordAccess = false;
1098 if ($this->enableLogging
) {
1099 $this->newlog('Record could not be created in this workspace in this branch', 1);
1106 debug('Internal ERROR: pid should not be less than zero!');
1108 // Yes new record, change $record_status to 'insert'
1111 // Nope... $id is a number
1112 $fieldArray = array();
1113 $recordAccess = $this->checkRecordUpdateAccess($table, $id, $incomingFieldArray, $hookObjectsArr);
1114 if (!$recordAccess) {
1115 if ($this->enableLogging
) {
1116 $propArr = $this->getRecordProperties($table, $id);
1117 $this->log($table, $id, 2, 0, 1, 'Attempt to modify record \'%s\' (%s) without permission. Or non-existing page.', 2, array($propArr['header'], $table . ':' . $id), $propArr['event_pid']);
1121 // Next check of the record permissions (internals)
1122 $recordAccess = $this->BE_USER
->recordEditAccessInternals($table, $id);
1123 if (!$recordAccess) {
1124 if ($this->enableLogging
) {
1125 $this->newlog('recordEditAccessInternals() check failed. [' . $this->BE_USER
->errorMsg
. ']', 1);
1128 // Here we fetch the PID of the record that we point to...
1129 $tempdata = $this->recordInfo($table, $id, 'pid' . ($GLOBALS['TCA'][$table]['ctrl']['versioningWS'] ?
',t3ver_wsid,t3ver_stage' : ''));
1130 $theRealPid = $tempdata['pid'];
1131 // Use the new id of the versionized record we're trying to write to:
1132 // (This record is a child record of a parent and has already been versionized.)
1133 if ($this->autoVersionIdMap
[$table][$id]) {
1134 // For the reason that creating a new version of this record, automatically
1135 // created related child records (e.g. "IRRE"), update the accordant field:
1136 $this->getVersionizedIncomingFieldArray($table, $id, $incomingFieldArray, $registerDBList);
1137 // Use the new id of the copied/versionized record:
1138 $id = $this->autoVersionIdMap
[$table][$id];
1139 $recordAccess = true;
1140 $this->autoVersioningUpdate
= true;
1141 } elseif (!$this->bypassWorkspaceRestrictions
&& ($errorCode = $this->BE_USER
->workspaceCannotEditRecord($table, $tempdata))) {
1142 $recordAccess = false;
1143 // Versioning is required and it must be offline version!
1144 // Check if there already is a workspace version
1145 $WSversion = BackendUtility
::getWorkspaceVersionOfRecord($this->BE_USER
->workspace
, $table, $id, 'uid,t3ver_oid');
1147 $id = $WSversion['uid'];
1148 $recordAccess = true;
1149 } elseif ($this->BE_USER
->workspaceAllowAutoCreation($table, $id, $theRealPid)) {
1150 // new version of a record created in a workspace - so always refresh pagetree to indicate there is a change in the workspace
1151 $this->pagetreeNeedsRefresh
= true;
1153 /** @var $tce DataHandler */
1154 $tce = GeneralUtility
::makeInstance(__CLASS__
);
1155 $tce->enableLogging
= $this->enableLogging
;
1156 // Setting up command for creating a new version of the record:
1158 $cmd[$table][$id]['version'] = array(
1161 // Default is to create a version of the individual records... element versioning that is.
1162 'label' => 'Auto-created for WS #' . $this->BE_USER
->workspace
1164 $tce->start(array(), $cmd);
1165 $tce->process_cmdmap();
1166 $this->errorLog
= array_merge($this->errorLog
, $tce->errorLog
);
1167 // If copying was successful, share the new uids (also of related children):
1168 if ($tce->copyMappingArray
[$table][$id]) {
1169 foreach ($tce->copyMappingArray
as $origTable => $origIdArray) {
1170 foreach ($origIdArray as $origId => $newId) {
1171 $this->uploadedFileArray
[$origTable][$newId] = $this->uploadedFileArray
[$origTable][$origId];
1172 $this->autoVersionIdMap
[$origTable][$origId] = $newId;
1175 ArrayUtility
::mergeRecursiveWithOverrule($this->RTEmagic_copyIndex
, $tce->RTEmagic_copyIndex
);
1176 // See where RTEmagic_copyIndex is used inside fillInFieldArray() for more information...
1177 // Update registerDBList, that holds the copied relations to child records:
1178 $registerDBList = array_merge($registerDBList, $tce->registerDBList
);
1179 // For the reason that creating a new version of this record, automatically
1180 // created related child records (e.g. "IRRE"), update the accordant field:
1181 $this->getVersionizedIncomingFieldArray($table, $id, $incomingFieldArray, $registerDBList);
1182 // Use the new id of the copied/versionized record:
1183 $id = $this->autoVersionIdMap
[$table][$id];
1184 $recordAccess = true;
1185 $this->autoVersioningUpdate
= true;
1186 } elseif ($this->enableLogging
) {
1187 $this->newlog('Could not be edited in offline workspace in the branch where found (failure state: \'' . $errorCode . '\'). Auto-creation of version failed!', 1);
1189 } elseif ($this->enableLogging
) {
1190 $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);
1194 // The default is 'update'
1197 // If access was granted above, proceed to create or update record:
1198 if (!$recordAccess) {
1202 // Here the "pid" is set IF NOT the old pid was a string pointing to a place in the subst-id array.
1203 list($tscPID) = BackendUtility
::getTSCpid($table, $id, $old_pid_value ?
$old_pid_value : $fieldArray['pid']);
1204 if ($status === 'new' && $table === 'pages') {
1205 $TSConfig = $this->getTCEMAIN_TSconfig($tscPID);
1206 if (isset($TSConfig['permissions.']) && is_array($TSConfig['permissions.'])) {
1207 $fieldArray = $this->setTSconfigPermissions($fieldArray, $TSConfig['permissions.']);
1210 // Processing of all fields in incomingFieldArray and setting them in $fieldArray
1211 $fieldArray = $this->fillInFieldArray($table, $id, $fieldArray, $incomingFieldArray, $theRealPid, $status, $tscPID);
1212 $newVersion_placeholderFieldArray = array();
1213 if ($createNewVersion) {
1214 // create a placeholder array with already processed field content
1215 $newVersion_placeholderFieldArray = $fieldArray;
1217 // NOTICE! All manipulation beyond this point bypasses both "excludeFields" AND possible "MM" relations / file uploads to field!
1218 // Forcing some values unto field array:
1219 // NOTICE: This overriding is potentially dangerous; permissions per field is not checked!!!
1220 $fieldArray = $this->overrideFieldArray($table, $fieldArray);
1221 if ($createNewVersion) {
1222 $newVersion_placeholderFieldArray = $this->overrideFieldArray($table, $newVersion_placeholderFieldArray);
1224 // Setting system fields
1225 if ($status == 'new') {
1226 if ($GLOBALS['TCA'][$table]['ctrl']['crdate']) {
1227 $fieldArray[$GLOBALS['TCA'][$table]['ctrl']['crdate']] = $GLOBALS['EXEC_TIME'];
1228 if ($createNewVersion) {
1229 $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['crdate']] = $GLOBALS['EXEC_TIME'];
1232 if ($GLOBALS['TCA'][$table]['ctrl']['cruser_id']) {
1233 $fieldArray[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']] = $this->userid
;
1234 if ($createNewVersion) {
1235 $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']] = $this->userid
;
1238 } elseif ($this->checkSimilar
) {
1239 // Removing fields which are equal to the current value:
1240 $fieldArray = $this->compareFieldArrayWithCurrentAndUnset($table, $id, $fieldArray);
1242 if ($GLOBALS['TCA'][$table]['ctrl']['tstamp'] && !empty($fieldArray)) {
1243 $fieldArray[$GLOBALS['TCA'][$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME'];
1244 if ($createNewVersion) {
1245 $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME'];
1248 // Set stage to "Editing" to make sure we restart the workflow
1249 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
1250 $fieldArray['t3ver_stage'] = 0;
1252 // Hook: processDatamap_postProcessFieldArray
1253 foreach ($hookObjectsArr as $hookObj) {
1254 if (method_exists($hookObj, 'processDatamap_postProcessFieldArray')) {
1255 $hookObj->processDatamap_postProcessFieldArray($status, $table, $id, $fieldArray, $this);
1258 // Performing insert/update. If fieldArray has been unset by some userfunction (see hook above), don't do anything
1259 // Kasper: Unsetting the fieldArray is dangerous; MM relations might be saved already and files could have been uploaded that are now "lost"
1260 if (is_array($fieldArray)) {
1261 if ($status == 'new') {
1262 if ($table === 'pages') {
1263 // for new pages always a refresh is needed
1264 $this->pagetreeNeedsRefresh
= true;
1267 // This creates a new version of the record with online placeholder and offline version
1268 if ($createNewVersion) {
1269 // new record created in a workspace - so always refresh pagetree to indicate there is a change in the workspace
1270 $this->pagetreeNeedsRefresh
= true;
1272 $newVersion_placeholderFieldArray['t3ver_label'] = 'INITIAL PLACEHOLDER';
1273 // Setting placeholder state value for temporary record
1274 $newVersion_placeholderFieldArray['t3ver_state'] = (string)new VersionState(VersionState
::NEW_PLACEHOLDER
);
1275 // Setting workspace - only so display of place holders can filter out those from other workspaces.
1276 $newVersion_placeholderFieldArray['t3ver_wsid'] = $this->BE_USER
->workspace
;
1277 $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['label']] = $this->getPlaceholderTitleForTableLabel($table);
1278 // Saving placeholder as 'original'
1279 $this->insertDB($table, $id, $newVersion_placeholderFieldArray, false);
1280 // For the actual new offline version, set versioning values to point to placeholder:
1281 $fieldArray['pid'] = -1;
1282 $fieldArray['t3ver_oid'] = $this->substNEWwithIDs
[$id];
1283 $fieldArray['t3ver_id'] = 1;
1284 // Setting placeholder state value for version (so it can know it is currently a new version...)
1285 $fieldArray['t3ver_state'] = (string)new VersionState(VersionState
::NEW_PLACEHOLDER_VERSION
);
1286 $fieldArray['t3ver_label'] = 'First draft version';
1287 $fieldArray['t3ver_wsid'] = $this->BE_USER
->workspace
;
1288 // When inserted, $this->substNEWwithIDs[$id] will be changed to the uid of THIS version and so the interface will pick it up just nice!
1289 $phShadowId = $this->insertDB($table, $id, $fieldArray, true, 0, true);
1291 // Processes fields of the placeholder record:
1292 $this->triggerRemapAction($table, $id, array($this, 'placeholderShadowing'), array($table, $phShadowId));
1293 // Hold auto-versionized ids of placeholders:
1294 $this->autoVersionIdMap
[$table][$this->substNEWwithIDs
[$id]] = $phShadowId;
1297 $this->insertDB($table, $id, $fieldArray, false, $incomingFieldArray['uid']);
1300 if ($table === 'pages') {
1301 // only a certain number of fields needs to be checked for updates
1302 // if $this->checkSimilar is TRUE, fields with unchanged values are already removed here
1303 $fieldsToCheck = array_intersect($this->pagetreeRefreshFieldsFromPages
, array_keys($fieldArray));
1304 if (!empty($fieldsToCheck)) {
1305 $this->pagetreeNeedsRefresh
= true;
1308 $this->updateDB($table, $id, $fieldArray);
1309 $this->placeholderShadowing($table, $id);
1312 // Hook: processDatamap_afterDatabaseOperations
1313 // Note: When using the hook after INSERT operations, you will only get the temporary NEW... id passed to your hook as $id,
1314 // but you can easily translate it to the real uid of the inserted record using the $this->substNEWwithIDs array.
1315 $this->hook_processDatamap_afterDatabaseOperations($hookObjectsArr, $status, $table, $id, $fieldArray);
1318 // Process the stack of relations to remap/correct
1319 $this->processRemapStack();
1320 $this->dbAnalysisStoreExec();
1321 $this->removeRegisteredFiles();
1322 // Hook: processDatamap_afterAllOperations
1323 // Note: When this hook gets called, all operations on the submitted data have been finished.
1324 foreach ($hookObjectsArr as $hookObj) {
1325 if (method_exists($hookObj, 'processDatamap_afterAllOperations')) {
1326 $hookObj->processDatamap_afterAllOperations($this);
1329 if ($this->isOuterMostInstance()) {
1330 $this->processClearCacheQueue();
1331 $this->resetElementsToBeDeleted();
1336 * Fix shadowing of data in case we are editing an offline version of a live "New" placeholder record:
1338 * @param string $table Table name
1339 * @param int $id Record uid
1342 public function placeholderShadowing($table, $id)
1344 if ($liveRec = BackendUtility
::getLiveVersionOfRecord($table, $id, '*')) {
1345 if (VersionState
::cast($liveRec['t3ver_state'])->indicatesPlaceholder()) {
1346 $justStoredRecord = BackendUtility
::getRecord($table, $id);
1347 $newRecord = array();
1348 $shadowCols = $GLOBALS['TCA'][$table]['ctrl']['shadowColumnsForNewPlaceholders'];
1349 $shadowCols .= ',' . $GLOBALS['TCA'][$table]['ctrl']['languageField'];
1350 $shadowCols .= ',' . $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
1351 $shadowCols .= ',' . $GLOBALS['TCA'][$table]['ctrl']['type'];
1352 $shadowCols .= ',' . $GLOBALS['TCA'][$table]['ctrl']['label'];
1353 $shadowColumns = array_unique(GeneralUtility
::trimExplode(',', $shadowCols, true));
1354 foreach ($shadowColumns as $fieldName) {
1355 if ((string)$justStoredRecord[$fieldName] !== (string)$liveRec[$fieldName] && isset($GLOBALS['TCA'][$table]['columns'][$fieldName]) && $fieldName !== 'uid' && $fieldName !== 'pid') {
1356 $newRecord[$fieldName] = $justStoredRecord[$fieldName];
1359 if (!empty($newRecord)) {
1360 if ($this->enableLogging
) {
1361 $this->newlog2('Shadowing done on fields <i>' . implode(',', array_keys($newRecord)) . '</i> in placeholder record ' . $table . ':' . $liveRec['uid'] . ' (offline version UID=' . $id . ')', $table, $liveRec['uid'], $liveRec['pid']);
1363 $this->updateDB($table, $liveRec['uid'], $newRecord);
1370 * Create a placeholder title for the label field that does match the field requirements
1372 * @param string $table The table name
1373 * @param string $placeholderContent Placeholder content to be used
1374 * @return string placeholder value
1376 public function getPlaceholderTitleForTableLabel($table, $placeholderContent = null)
1378 if ($placeholderContent === null) {
1379 $placeholderContent = 'PLACEHOLDER';
1382 $labelPlaceholder = '[' . $placeholderContent . ', WS#' . $this->BE_USER
->workspace
. ']';
1383 $labelField = $GLOBALS['TCA'][$table]['ctrl']['label'];
1384 if (!isset($GLOBALS['TCA'][$table]['columns'][$labelField]['config']['eval'])) {
1385 return $labelPlaceholder;
1387 $evalCodesArray = GeneralUtility
::trimExplode(',', $GLOBALS['TCA'][$table]['columns'][$labelField]['config']['eval'], true);
1388 $transformedLabel = $this->checkValue_input_Eval($labelPlaceholder, $evalCodesArray, '');
1389 return isset($transformedLabel['value']) ?
$transformedLabel['value'] : $labelPlaceholder;
1393 * Filling in the field array
1394 * $this->excludedTablesAndFields is used to filter fields if needed.
1396 * @param string $table Table name
1397 * @param int $id Record ID
1398 * @param array $fieldArray Default values, Preset $fieldArray with 'pid' maybe (pid and uid will be not be overridden anyway)
1399 * @param array $incomingFieldArray Is which fields/values you want to set. There are processed and put into $fieldArray if OK
1400 * @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.
1401 * @param string $status Is 'new' or 'update'
1402 * @param int $tscPID TSconfig PID
1403 * @return array Field Array
1405 public function fillInFieldArray($table, $id, $fieldArray, $incomingFieldArray, $realPid, $status, $tscPID)
1408 $originalLanguageRecord = null;
1409 $originalLanguage_diffStorage = null;
1410 $diffStorageFlag = false;
1411 // Setting 'currentRecord' and 'checkValueRecord':
1412 if (strstr($id, 'NEW')) {
1413 // Must have the 'current' array - not the values after processing below...
1414 $currentRecord = ($checkValueRecord = $fieldArray);
1415 // IF $incomingFieldArray is an array, overlay it.
1416 // 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...
1417 if (is_array($incomingFieldArray) && is_array($checkValueRecord)) {
1418 ArrayUtility
::mergeRecursiveWithOverrule($checkValueRecord, $incomingFieldArray);
1421 // We must use the current values as basis for this!
1422 $currentRecord = ($checkValueRecord = $this->recordInfo($table, $id, '*'));
1423 // This is done to make the pid positive for offline versions; Necessary to have diff-view for pages_language_overlay in workspaces.
1424 BackendUtility
::fixVersioningPid($table, $currentRecord);
1425 // Get original language record if available:
1426 if (is_array($currentRecord) && $GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField'] && $GLOBALS['TCA'][$table]['ctrl']['languageField'] && $currentRecord[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0 && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] && (int)$currentRecord[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] > 0) {
1427 $lookUpTable = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable'] ?
: $table;
1428 $originalLanguageRecord = $this->recordInfo($lookUpTable, $currentRecord[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']], '*');
1429 BackendUtility
::workspaceOL($lookUpTable, $originalLanguageRecord);
1430 $originalLanguage_diffStorage = unserialize($currentRecord[$GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']]);
1433 $this->checkValue_currentRecord
= $checkValueRecord;
1434 // In the following all incoming value-fields are tested:
1435 // - Are the user allowed to change the field?
1436 // - Is the field uid/pid (which are already set)
1437 // - perms-fields for pages-table, then do special things...
1438 // - If the field is nothing of the above and the field is configured in TCA, the fieldvalues are evaluated by ->checkValue
1439 // If everything is OK, the field is entered into $fieldArray[]
1440 foreach ($incomingFieldArray as $field => $fieldValue) {
1441 if (isset($this->excludedTablesAndFields
[$table . '-' . $field]) ||
$this->data_disableFields
[$table][$id][$field]) {
1445 // The field must be editable.
1446 // Checking if a value for language can be changed:
1447 $languageDeny = $GLOBALS['TCA'][$table]['ctrl']['languageField'] && (string)$GLOBALS['TCA'][$table]['ctrl']['languageField'] === (string)$field && !$this->BE_USER
->checkLanguageAccess($fieldValue);
1448 if ($languageDeny) {
1455 // Nothing happens, already set
1457 case 'perms_userid':
1458 case 'perms_groupid':
1461 case 'perms_everybody':
1462 // Permissions can be edited by the owner or the administrator
1463 if ($table == 'pages' && ($this->admin ||
$status == 'new' ||
$this->pageInfo($id, 'perms_userid') == $this->userid
)) {
1464 $value = (int)$fieldValue;
1466 case 'perms_userid':
1467 $fieldArray[$field] = $value;
1469 case 'perms_groupid':
1470 $fieldArray[$field] = $value;
1473 if ($value >= 0 && $value < pow(2, 5)) {
1474 $fieldArray[$field] = $value;
1485 case 't3ver_tstamp':
1486 // t3ver_label is not here because it CAN be edited as a regular field!
1489 if (isset($GLOBALS['TCA'][$table]['columns'][$field])) {
1490 // Evaluating the value
1491 $res = $this->checkValue($table, $field, $fieldValue, $id, $status, $realPid, $tscPID);
1492 if (array_key_exists('value', $res)) {
1493 $fieldArray[$field] = $res['value'];
1495 // Add the value of the original record to the diff-storage content:
1496 if ($this->updateModeL10NdiffData
&& $GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']) {
1497 $originalLanguage_diffStorage[$field] = $this->updateModeL10NdiffDataClear ?
'' : $originalLanguageRecord[$field];
1498 $diffStorageFlag = true;
1500 // If autoversioning is happening we need to perform a nasty hack. The case is parallel to a similar hack inside checkValue_group_select_file().
1501 // 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.
1502 // 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.
1503 // 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.
1504 // 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 !
1505 if ($this->autoVersioningUpdate
=== true) {
1506 if (is_array($this->RTEmagic_copyIndex
[$table][$id][$field])) {
1507 foreach ($this->RTEmagic_copyIndex
[$table][$id][$field] as $oldRTEmagicName => $newRTEmagicName) {
1508 $fieldArray[$field] = str_replace(' src="' . $oldRTEmagicName . '"', ' src="' . $newRTEmagicName . '"', $fieldArray[$field]);
1512 } elseif ($GLOBALS['TCA'][$table]['ctrl']['origUid'] === $field) {
1513 // Allow value for original UID to pass by...
1514 $fieldArray[$field] = $fieldValue;
1518 // Add diff-storage information:
1519 if ($diffStorageFlag && !isset($fieldArray[$GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']])) {
1520 // 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...
1521 $fieldArray[$GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']] = serialize($originalLanguage_diffStorage);
1523 // Checking for RTE-transformations of fields:
1524 $types_fieldConfig = BackendUtility
::getTCAtypes($table, $currentRecord);
1525 $theTypeString = null;
1526 if (is_array($types_fieldConfig)) {
1527 foreach ($types_fieldConfig as $vconf) {
1528 // RTE transformations:
1529 if ($this->dontProcessTransformations ||
!isset($fieldArray[$vconf['field']])) {
1533 // Look for transformation flag:
1534 if ((string)$incomingFieldArray['_TRANSFORM_' . $vconf['field']] === 'RTE') {
1535 if ($theTypeString === null) {
1536 $theTypeString = BackendUtility
::getTCAtypeValue($table, $currentRecord);
1538 $RTEsetup = $this->BE_USER
->getTSConfig('RTE', BackendUtility
::getPagesTSconfig($tscPID));
1539 $thisConfig = BackendUtility
::RTEsetup($RTEsetup['properties'], $table, $vconf['field'], $theTypeString);
1540 $fieldArray[$vconf['field']] = $this->transformRichtextContentToDatabase(
1541 $fieldArray[$vconf['field']], $table, $vconf['field'], $vconf['spec'], $thisConfig, $currentRecord['pid']
1546 // Return fieldArray
1551 * Performs transformation of content from richtext element to database.
1553 * @param string $value Value to transform.
1554 * @param string $table The table name
1555 * @param string $field The field name
1556 * @param array $defaultExtras Default extras configuration of this field - typically "richtext:rte_transform"
1557 * @param array $thisConfig Configuration for RTEs; A mix between TSconfig and others. Configuration for additional transformation information
1558 * @param int $pid PID value of record (true parent page id)
1559 * @return string Transformed content
1561 protected function transformRichtextContentToDatabase($value, $table, $field, $defaultExtras, $thisConfig, $pid)
1563 if ($defaultExtras['rte_transform']) {
1564 // Initialize transformation:
1565 $parseHTML = GeneralUtility
::makeInstance(RteHtmlParser
::class);
1566 $parseHTML->init($table . ':' . $field, $pid);
1567 // Perform transformation:
1568 $value = $parseHTML->RTE_transform($value, $defaultExtras, 'db', $thisConfig);
1573 /*********************************************
1575 * Evaluation of input values
1577 ********************************************/
1579 * Evaluates a value according to $table/$field settings.
1580 * This function is for real database fields - NOT FlexForm "pseudo" fields.
1581 * 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() )
1583 * @param string $table Table name
1584 * @param string $field Field name
1585 * @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.
1586 * @param string $id The record-uid, mainly - but not exclusively - used for logging
1587 * @param string $status 'update' or 'new' flag
1588 * @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.
1589 * @param int $tscPID TSconfig PID
1590 * @return array Returns the evaluated $value as key "value" in this array. Can be checked with isset($res['value']) ...
1592 public function checkValue($table, $field, $value, $id, $status, $realPid, $tscPID)
1597 // Processing special case of field pages.doktype
1598 if (($table === 'pages' ||
$table === 'pages_language_overlay') && $field === 'doktype') {
1599 // If the user may not use this specific doktype, we issue a warning
1600 if (!($this->admin || GeneralUtility
::inList($this->BE_USER
->groupData
['pagetypes_select'], $value))) {
1601 if ($this->enableLogging
) {
1602 $propArr = $this->getRecordProperties($table, $id);
1603 $this->log($table, $id, 5, 0, 1, 'You cannot change the \'doktype\' of page \'%s\' to the desired value.', 1, array($propArr['header']), $propArr['event_pid']);
1607 if ($status == 'update') {
1608 // This checks 1) if we should check for disallowed tables and 2) if there are records from disallowed tables on the current page
1609 $onlyAllowedTables = isset($GLOBALS['PAGES_TYPES'][$value]['onlyAllowedTables']) ?
$GLOBALS['PAGES_TYPES'][$value]['onlyAllowedTables'] : $GLOBALS['PAGES_TYPES']['default']['onlyAllowedTables'];
1610 if ($onlyAllowedTables) {
1611 $theWrongTables = $this->doesPageHaveUnallowedTables($id, $value);
1612 if ($theWrongTables) {
1613 if ($this->enableLogging
) {
1614 $propArr = $this->getRecordProperties($table, $id);
1615 $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, array($propArr['header'], $theWrongTables), $propArr['event_pid']);
1624 if ((int)$id !== 0) {
1625 // Get current value:
1626 $curValueRec = $this->recordInfo($table, $id, $field);
1627 // isset() won't work here, since values can be NULL
1628 if ($curValueRec !== null && array_key_exists($field, $curValueRec)) {
1629 $curValue = $curValueRec[$field];
1633 // Getting config for the field
1634 $tcaFieldConf = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
1636 // Create $recFID only for those types that need it
1638 $tcaFieldConf['type'] === 'flex'
1639 ||
$tcaFieldConf['type'] === 'group' && ($tcaFieldConf['internal_type'] === 'file' ||
$tcaFieldConf['internal_type'] === 'file_reference')
1641 $recFID = $table . ':' . $id . ':' . $field;
1646 // Perform processing:
1647 $res = $this->checkValue_SW($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $realPid, $recFID, $field, $this->uploadedFileArray
[$table][$id][$field], $tscPID);
1652 * Branches out evaluation of a field value based on its type as configured in $GLOBALS['TCA']
1653 * Can be called for FlexForm pseudo fields as well, BUT must not have $field set if so.
1655 * @param array $res The result array. The processed value (if any!) is set in the "value" key.
1656 * @param string $value The value to set.
1657 * @param array $tcaFieldConf Field configuration from $GLOBALS['TCA']
1658 * @param string $table Table name
1659 * @param int $id UID of record
1660 * @param mixed $curValue Current value of the field
1661 * @param string $status 'update' or 'new' flag
1662 * @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.
1663 * @param string $recFID Field identifier [table:uid:field] for flexforms
1664 * @param string $field Field name. Must NOT be set if the call is for a flexform field (since flexforms are not allowed within flexforms).
1665 * @param array $uploadedFiles
1666 * @param int $tscPID TSconfig PID
1667 * @param array $additionalData Additional data to be forwarded to sub-processors
1668 * @return array Returns the evaluated $value as key "value" in this array.
1670 public function checkValue_SW($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $realPid, $recFID, $field, $uploadedFiles, $tscPID, array $additionalData = null)
1672 // Convert to NULL value if defined in TCA
1673 if ($value === null && !empty($tcaFieldConf['eval']) && GeneralUtility
::inList($tcaFieldConf['eval'], 'null')) {
1674 $res = array('value' => null);
1678 switch ($tcaFieldConf['type']) {
1680 $res = $this->checkValueForText($value, $tcaFieldConf);
1683 case 'imageManipulation':
1685 $res['value'] = $value;
1688 $res = $this->checkValueForInput($value, $tcaFieldConf, $table, $id, $realPid, $field);
1691 $res = $this->checkValueForCheck($res, $value, $tcaFieldConf, $table, $id, $realPid, $field);
1694 $res = $this->checkValueForRadio($res, $value, $tcaFieldConf, $table, $id, $realPid, $field);
1698 $res = $this->checkValueForGroupSelect($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $recFID, $uploadedFiles, $field);
1701 $res = $this->checkValueForInline($res, $value, $tcaFieldConf, $table, $id, $status, $field, $additionalData);
1704 // FlexForms are only allowed for real fields.
1706 $res = $this->checkValueForFlex($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $realPid, $recFID, $tscPID, $uploadedFiles, $field);
1716 * Evaluate "text" type values.
1718 * @param string $value The value to set.
1719 * @param array $tcaFieldConf Field configuration from TCA
1720 * @return array $res The result array. The processed value (if any!) is set in the "value" key.
1722 protected function checkValueForText($value, $tcaFieldConf)
1724 if (!isset($tcaFieldConf['eval']) ||
$tcaFieldConf['eval'] === '') {
1725 return array('value' => $value);
1727 $cacheId = $this->getFieldEvalCacheIdentifier($tcaFieldConf['eval']);
1728 if ($this->runtimeCache
->has($cacheId)) {
1729 $evalCodesArray = $this->runtimeCache
->get($cacheId);
1731 $evalCodesArray = GeneralUtility
::trimExplode(',', $tcaFieldConf['eval'], true);
1732 $this->runtimeCache
->set($cacheId, $evalCodesArray);
1734 return $this->checkValue_text_Eval($value, $evalCodesArray, $tcaFieldConf['is_in']);
1738 * Evaluate "input" type values.
1740 * @param string $value The value to set.
1741 * @param array $tcaFieldConf Field configuration from TCA
1742 * @param string $table Table name
1743 * @param int $id UID of record
1744 * @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.
1745 * @param string $field Field name
1746 * @return array $res The result array. The processed value (if any!) is set in the "value" key.
1748 protected function checkValueForInput($value, $tcaFieldConf, $table, $id, $realPid, $field)
1750 // Handle native date/time fields
1751 $isDateOrDateTimeField = false;
1754 if (isset($tcaFieldConf['dbType']) && ($tcaFieldConf['dbType'] === 'date' ||
$tcaFieldConf['dbType'] === 'datetime')) {
1755 if (empty($value)) {
1758 $isDateOrDateTimeField = true;
1759 $dateTimeFormats = $this->databaseConnection
->getDateTimeFormats($table);
1760 // Convert the date/time into a timestamp for the sake of the checks
1761 $emptyValue = $dateTimeFormats[$tcaFieldConf['dbType']]['empty'];
1762 $format = $dateTimeFormats[$tcaFieldConf['dbType']]['format'];
1763 // At this point in the processing, the timestamps are still based on UTC
1764 $timeZone = new \
DateTimeZone('UTC');
1765 $dateTime = \DateTime
::createFromFormat('!' . $format, $value, $timeZone);
1766 $value = $value === $emptyValue ?
0 : $dateTime->getTimestamp();
1769 // Secures the string-length to be less than max.
1770 if ((int)$tcaFieldConf['max'] > 0) {
1771 /** @var CharsetConverter $charsetConverter */
1772 $charsetConverter = GeneralUtility
::makeInstance(CharsetConverter
::class);
1773 $value = $charsetConverter->substr('utf-8', (string)$value, 0, (int)$tcaFieldConf['max']);
1775 // Checking range of value:
1776 // @todo: The "checkbox" option was removed for type=input, this check could be probably relaxed?
1777 if ($tcaFieldConf['range'] && $value != $tcaFieldConf['checkbox'] && (int)$value !== (int)$tcaFieldConf['default']) {
1778 if (isset($tcaFieldConf['range']['upper']) && (int)$value > (int)$tcaFieldConf['range']['upper']) {
1779 $value = $tcaFieldConf['range']['upper'];
1781 if (isset($tcaFieldConf['range']['lower']) && (int)$value < (int)$tcaFieldConf['range']['lower']) {
1782 $value = $tcaFieldConf['range']['lower'];
1786 if (empty($tcaFieldConf['eval'])) {
1787 $res = array('value' => $value);
1789 // Process evaluation settings:
1790 $cacheId = $this->getFieldEvalCacheIdentifier($tcaFieldConf['eval']);
1791 if ($this->runtimeCache
->has($cacheId)) {
1792 $evalCodesArray = $this->runtimeCache
->get($cacheId);
1794 $evalCodesArray = GeneralUtility
::trimExplode(',', $tcaFieldConf['eval'], true);
1795 $this->runtimeCache
->set($cacheId, $evalCodesArray);
1798 $res = $this->checkValue_input_Eval($value, $evalCodesArray, $tcaFieldConf['is_in']);
1800 // Process UNIQUE settings:
1801 // 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...
1802 if ($field && $realPid >= 0 && !empty($res['value'])) {
1803 if (in_array('uniqueInPid', $evalCodesArray, true)) {
1804 $res['value'] = $this->getUnique($table, $field, $res['value'], $id, $realPid);
1806 if ($res['value'] && in_array('unique', $evalCodesArray, true)) {
1807 $res['value'] = $this->getUnique($table, $field, $res['value'], $id);
1812 // Handle native date/time fields
1813 if ($isDateOrDateTimeField) {
1814 // Convert the timestamp back to a date/time
1815 $res['value'] = $res['value'] ?
date($format, $res['value']) : $emptyValue;
1821 * Evaluates 'check' type values.
1823 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
1824 * @param string $value The value to set.
1825 * @param array $tcaFieldConf Field configuration from TCA
1826 * @param string $table Table name
1827 * @param int $id UID of record
1828 * @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.
1829 * @param string $field Field name
1830 * @return array Modified $res array
1832 protected function checkValueForCheck($res, $value, $tcaFieldConf, $table, $id, $realPid, $field)
1834 $itemC = count($tcaFieldConf['items']);
1838 $maxV = pow(2, $itemC) - 1;
1842 if ($value > $maxV) {
1845 if ($field && $realPid >= 0 && $value > 0 && !empty($tcaFieldConf['eval'])) {
1846 $evalCodesArray = GeneralUtility
::trimExplode(',', $tcaFieldConf['eval'], true);
1847 $otherRecordsWithSameValue = array();
1848 $maxCheckedRecords = 0;
1849 if (in_array('maximumRecordsCheckedInPid', $evalCodesArray, true)) {
1850 $otherRecordsWithSameValue = $this->getRecordsWithSameValue($table, $id, $field, $value, $realPid);
1851 $maxCheckedRecords = (int)$tcaFieldConf['validation']['maximumRecordsCheckedInPid'];
1853 if (in_array('maximumRecordsChecked', $evalCodesArray, true)) {
1854 $otherRecordsWithSameValue = $this->getRecordsWithSameValue($table, $id, $field, $value);
1855 $maxCheckedRecords = (int)$tcaFieldConf['validation']['maximumRecordsChecked'];
1858 // there are more than enough records with value "1" in the DB
1859 // if so, set this value to "0" again
1860 if ($maxCheckedRecords && count($otherRecordsWithSameValue) >= $maxCheckedRecords) {
1862 if ($this->enableLogging
) {
1863 $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, array($GLOBALS['LANG']->sL(BackendUtility
::getItemLabel($table, $field)), $maxCheckedRecords));
1867 $res['value'] = $value;
1872 * Evaluates 'radio' type values.
1874 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
1875 * @param string $value The value to set.
1876 * @param array $tcaFieldConf Field configuration from TCA
1877 * @param array $table The table of the record
1878 * @param int $id The id of the record
1879 * @param int $pid The pid of the record
1880 * @param string $field The field to check
1881 * @return array Modified $res array
1883 protected function checkValueForRadio($res, $value, $tcaFieldConf, $table, $id, $pid, $field)
1885 if (is_array($tcaFieldConf['items'])) {
1886 foreach ($tcaFieldConf['items'] as $set) {
1887 if ((string)$set[1] === (string)$value) {
1888 $res['value'] = $value;
1894 // if no value was found and an itemsProcFunc is defined, check that for the value
1895 if ($tcaFieldConf['itemsProcFunc'] && empty($res['value'])) {
1896 $processingService = GeneralUtility
::makeInstance(ItemProcessingService
::class);
1897 $processedItems = $processingService->getProcessingItems($table, $pid, $field, $this->checkValue_currentRecord
,
1898 $tcaFieldConf, $tcaFieldConf['items']);
1900 foreach ($processedItems as $set) {
1901 if ((string)$set[1] === (string)$value) {
1902 $res['value'] = $value;
1912 * Evaluates 'group' or 'select' type values.
1914 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
1915 * @param string $value The value to set.
1916 * @param array $tcaFieldConf Field configuration from TCA
1917 * @param string $table Table name
1918 * @param int $id UID of record
1919 * @param mixed $curValue Current value of the field
1920 * @param string $status 'update' or 'new' flag
1921 * @param string $recFID Field identifier [table:uid:field] for flexforms
1922 * @param array $uploadedFiles
1923 * @param string $field Field name
1924 * @return array Modified $res array
1926 protected function checkValueForGroupSelect($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $recFID, $uploadedFiles, $field)
1928 // Detecting if value sent is an array and if so, implode it around a comma:
1929 if (is_array($value)) {
1930 $value = implode(',', $value);
1932 // 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.
1933 // Anyway, this should NOT disturb anything else:
1934 $value = $this->convNumEntityToByteValue($value);
1935 // When values are sent as group or select they come as comma-separated values which are exploded by this function:
1936 $valueArray = $this->checkValue_group_select_explodeSelectGroupValue($value);
1937 // If multiple is not set, remove duplicates:
1938 if (!$tcaFieldConf['multiple']) {
1939 $valueArray = array_unique($valueArray);
1941 // If an exclusive key is found, discard all others:
1942 if ($tcaFieldConf['type'] == 'select' && $tcaFieldConf['exclusiveKeys']) {
1943 $exclusiveKeys = GeneralUtility
::trimExplode(',', $tcaFieldConf['exclusiveKeys']);
1944 foreach ($valueArray as $index => $key) {
1945 if (in_array($key, $exclusiveKeys, true)) {
1946 $valueArray = array($index => $key);
1951 // 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?)
1952 // 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!!
1953 $valueArray = $this->applyFiltersToValues($tcaFieldConf, $valueArray);
1954 // Checking for select / authMode, removing elements from $valueArray if any of them is not allowed!
1955 if ($tcaFieldConf['type'] == 'select' && $tcaFieldConf['authMode']) {
1956 $preCount = count($valueArray);
1957 foreach ($valueArray as $index => $key) {
1958 if (!$this->BE_USER
->checkAuthMode($table, $field, $key, $tcaFieldConf['authMode'])) {
1959 unset($valueArray[$index]);
1962 // 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.
1963 if ($preCount && empty($valueArray)) {
1968 if ($tcaFieldConf['type'] == 'group') {
1969 switch ($tcaFieldConf['internal_type']) {
1970 case 'file_reference':
1973 $valueArray = $this->checkValue_group_select_file($valueArray, $tcaFieldConf, $curValue, $uploadedFiles, $status, $table, $id, $recFID);
1976 $valueArray = $this->checkValue_group_select_processDBdata($valueArray, $tcaFieldConf, $id, $status, 'group', $table, $field);
1980 // For select types which has a foreign table attached:
1981 $unsetResult = false;
1982 if ($tcaFieldConf['type'] == 'select' && $tcaFieldConf['foreign_table']) {
1983 // check, if there is a NEW... id in the value, that should be substituted later
1984 if (strpos($value, 'NEW') !== false) {
1985 $this->remapStackRecords
[$table][$id] = array('remapStackIndex' => count($this->remapStack
));
1986 $this->addNewValuesToRemapStackChildIds($valueArray);
1987 $this->remapStack
[] = array(
1988 'func' => 'checkValue_group_select_processDBdata',
1989 'args' => array($valueArray, $tcaFieldConf, $id, $status, 'select', $table, $field),
1990 'pos' => array('valueArray' => 0, 'tcaFieldConf' => 1, 'id' => 2, 'table' => 5),
1993 $unsetResult = true;
1995 $valueArray = $this->checkValue_group_select_processDBdata($valueArray, $tcaFieldConf, $id, $status, 'select', $table, $field);
1998 if (!$unsetResult) {
1999 $newVal = $this->checkValue_checkMax($tcaFieldConf, $valueArray);
2000 $res['value'] = $this->castReferenceValue(implode(',', $newVal), $tcaFieldConf);
2002 unset($res['value']);
2008 * Applies the filter methods from a column's TCA configuration to a value array.
2010 * @param array $tcaFieldConfiguration
2011 * @param array $values
2012 * @return array|mixed
2013 * @throws \RuntimeException
2015 protected function applyFiltersToValues(array $tcaFieldConfiguration, array $values)
2017 if (empty($tcaFieldConfiguration['filter']) ||
!is_array($tcaFieldConfiguration['filter'])) {
2020 foreach ($tcaFieldConfiguration['filter'] as $filter) {
2021 if (empty($filter['userFunc'])) {
2024 $parameters = $filter['parameters'] ?
: array();
2025 $parameters['values'] = $values;
2026 $parameters['tcaFieldConfig'] = $tcaFieldConfiguration;
2027 $values = GeneralUtility
::callUserFunction($filter['userFunc'], $parameters, $this);
2028 if (!is_array($values)) {
2029 throw new \
RuntimeException('Failed calling filter userFunc.', 1336051942);
2036 * Handling files for group/select function
2038 * @param array $valueArray Array of incoming file references. Keys are numeric, values are files (basically, this is the exploded list of incoming files)
2039 * @param array $tcaFieldConf Configuration array from TCA of the field
2040 * @param string $curValue Current value of the field
2041 * @param array $uploadedFileArray Array of uploaded files, if any
2042 * @param string $status 'update' or 'new' flag
2043 * @param string $table tablename of record
2044 * @param int $id UID of record
2045 * @param string $recFID Field identifier [table:uid:field] for flexforms
2046 * @return array Modified value array
2048 * @throws \RuntimeException
2050 public function checkValue_group_select_file($valueArray, $tcaFieldConf, $curValue, $uploadedFileArray, $status, $table, $id, $recFID)
2052 // If file handling should NOT be bypassed, do processing:
2053 if (!$this->bypassFileHandling
) {
2054 // If any files are uploaded, add them to value array
2055 // Numeric index means that there are multiple files
2056 if (isset($uploadedFileArray[0])) {
2057 $uploadedFiles = $uploadedFileArray;
2059 // There is only one file
2060 $uploadedFiles = array($uploadedFileArray);
2062 foreach ($uploadedFiles as $uploadedFileArray) {
2063 if (!empty($uploadedFileArray['name']) && $uploadedFileArray['tmp_name'] !== 'none') {
2064 $valueArray[] = $uploadedFileArray['tmp_name'];
2065 $this->alternativeFileName
[$uploadedFileArray['tmp_name']] = $uploadedFileArray['name'];
2068 // Creating fileFunc object.
2069 if (!$this->fileFunc
) {
2070 $this->fileFunc
= GeneralUtility
::makeInstance(BasicFileUtility
::class);
2072 // Setting permitted extensions.
2073 $all_files = array();
2074 $all_files['webspace']['allow'] = $tcaFieldConf['allowed'];
2075 $all_files['webspace']['deny'] = $tcaFieldConf['disallowed'] ?
: '*';
2076 $all_files['ftpspace'] = $all_files['webspace'];
2077 $this->fileFunc
->init('', $all_files);
2079 // If there is an upload folder defined:
2080 if ($tcaFieldConf['uploadfolder'] && $tcaFieldConf['internal_type'] == 'file') {
2081 $currentFilesForHistory = null;
2082 // If filehandling should NOT be bypassed, do processing:
2083 if (!$this->bypassFileHandling
) {
2085 $propArr = $this->getRecordProperties($table, $id);
2086 // Get destrination path:
2087 $dest = $this->destPathFromUploadFolder($tcaFieldConf['uploadfolder']);
2088 // If we are updating:
2089 if ($status == 'update') {
2090 // Traverse the input values and convert to absolute filenames in case the update happens to an autoVersionized record.
2091 // 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!
2092 // 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_.
2093 // 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.
2094 // Illustration of the problem comes here:
2095 // 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.
2096 // 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.
2097 // 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.
2098 // 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.
2099 if ($this->autoVersioningUpdate
=== true) {
2100 foreach ($valueArray as $key => $theFile) {
2101 // If it is an already attached file...
2102 if ($theFile === basename($theFile)) {
2103 $valueArray[$key] = PATH_site
. $tcaFieldConf['uploadfolder'] . '/' . $theFile;
2107 // Finding the CURRENT files listed, either from MM or from the current record.
2108 $theFileValues = array();
2109 // If MM relations for the files also!
2110 if ($tcaFieldConf['MM']) {
2111 $dbAnalysis = $this->createRelationHandlerInstance();
2112 /** @var $dbAnalysis RelationHandler */
2113 $dbAnalysis->start('', 'files', $tcaFieldConf['MM'], $id);
2114 foreach ($dbAnalysis->itemArray
as $item) {
2116 $theFileValues[] = $item['id'];
2120 $theFileValues = GeneralUtility
::trimExplode(',', $curValue, true);
2122 $currentFilesForHistory = implode(',', $theFileValues);
2123 // DELETE files: If existing files were found, traverse those and register files for deletion which has been removed:
2124 if (!empty($theFileValues)) {
2125 // 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!)
2126 foreach ($valueArray as $key => $theFile) {
2127 if ($theFile && !strstr(GeneralUtility
::fixWindowsFilePath($theFile), '/')) {
2128 $theFileValues = ArrayUtility
::removeArrayEntryByValue($theFileValues, $theFile);
2131 // This array contains the filenames in the uploadfolder that should be deleted:
2132 foreach ($theFileValues as $key => $theFile) {
2133 $theFile = trim($theFile);
2134 if (@is_file
(($dest . '/' . $theFile))) {
2135 $this->removeFilesStore
[] = $dest . '/' . $theFile;
2136 } elseif ($this->enableLogging
&& $theFile) {
2137 $this->log($table, $id, 5, 0, 1, 'Could not delete file \'%s\' (does not exist). (%s)', 10, array($dest . '/' . $theFile, $recFID), $propArr['event_pid']);
2142 // Traverse the submitted values:
2143 foreach ($valueArray as $key => $theFile) {
2145 $maxSize = (int)$tcaFieldConf['max_size'];
2146 // Must be cleared. Else a faulty fileref may be inserted if the below code returns an error!
2148 // a FAL file was added, now resolve the file object and get the absolute path
2149 // @todo in future versions this needs to be modified to handle FAL objects natively
2150 if (!empty($theFile) && MathUtility
::canBeInterpretedAsInteger($theFile)) {
2151 $fileObject = ResourceFactory
::getInstance()->getFileObject($theFile);
2152 $theFile = $fileObject->getForLocalProcessing(false);
2154 // NEW FILES? If the value contains '/' it indicates, that the file
2155 // is new and should be added to the uploadsdir (whether its absolute or relative does not matter here)
2156 if (strstr(GeneralUtility
::fixWindowsFilePath($theFile), '/')) {
2157 // Check various things before copying file:
2158 // File and destination must exist
2159 if (@is_dir
($dest) && (@is_file
($theFile) || @is_uploaded_file
($theFile))) {
2161 if (is_uploaded_file($theFile) && $theFile == $uploadedFileArray['tmp_name']) {
2162 $fileSize = $uploadedFileArray['size'];
2164 $fileSize = filesize($theFile);
2167 if (!$maxSize ||
$fileSize <= $maxSize * 1024) {
2168 // Prepare filename:
2169 $theEndFileName = isset($this->alternativeFileName
[$theFile]) ?
$this->alternativeFileName
[$theFile] : $theFile;
2170 $fI = GeneralUtility
::split_fileref($theEndFileName);
2171 // Check for allowed extension:
2172 if ($this->fileFunc
->checkIfAllowed($fI['fileext'], $dest, $theEndFileName)) {
2173 $theDestFile = $this->fileFunc
->getUniqueName($this->fileFunc
->cleanFileName($fI['file']), $dest);
2174 // If we have a unique destination filename, then write the file:
2176 GeneralUtility
::upload_copy_move($theFile, $theDestFile);
2177 // Hook for post-processing the upload action
2178 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processUpload'])) {
2179 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processUpload'] as $classRef) {
2180 $hookObject = GeneralUtility
::getUserObj($classRef);
2181 if (!$hookObject instanceof DataHandlerProcessUploadHookInterface
) {
2182 throw new \
UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Core\\DataHandling\\DataHandlerProcessUploadHookInterface', 1279962349);
2184 $hookObject->processUpload_postProcessAction($theDestFile, $this);
2187 $this->copiedFileMap
[$theFile] = $theDestFile;
2189 if ($this->enableLogging
&& !@is_file
($theDestFile)) {
2190 $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, array($theFile, dirname($theDestFile), $recFID), $propArr['event_pid']);
2192 } elseif ($this->enableLogging
) {
2193 $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: No destination file (%s) possible!. (%s)', 11, array($theFile, $theDestFile, $recFID), $propArr['event_pid']);
2195 } elseif ($this->enableLogging
) {
2196 $this->log($table, $id, 5, 0, 1, 'File extension \'%s\' not allowed. (%s)', 12, array($fI['fileext'], $recFID), $propArr['event_pid']);
2198 } elseif ($this->enableLogging
) {
2199 $this->log($table, $id, 5, 0, 1, 'Filesize (%s) of file \'%s\' exceeds limit (%s). (%s)', 13, array(GeneralUtility
::formatSize($fileSize), $theFile, GeneralUtility
::formatSize($maxSize * 1024), $recFID), $propArr['event_pid']);
2201 } elseif ($this->enableLogging
) {
2202 $this->log($table, $id, 5, 0, 1, 'The destination (%s) or the source file (%s) does not exist. (%s)', 14, array($dest, $theFile, $recFID), $propArr['event_pid']);
2204 // If the destination file was created, we will set the new filename in the value array, otherwise unset the entry in the value array!
2205 if (@is_file
($theDestFile)) {
2206 $info = GeneralUtility
::split_fileref($theDestFile);
2207 // The value is set to the new filename
2208 $valueArray[$key] = $info['file'];
2210 // The value is set to the new filename
2211 unset($valueArray[$key]);
2216 // 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!
2217 if ($tcaFieldConf['MM']) {
2218 /** @var $dbAnalysis RelationHandler */
2219 $dbAnalysis = $this->createRelationHandlerInstance();
2221 $dbAnalysis->tableArray
['files'] = array();
2222 foreach ($valueArray as $key => $theFile) {
2224 $dbAnalysis->itemArray
[]['id'] = $theFile;
2226 if ($status == 'update') {
2227 $dbAnalysis->writeMM($tcaFieldConf['MM'], $id, 0);
2228 $newFiles = implode(',', $dbAnalysis->getValueArray());
2229 list(, , $recFieldName) = explode(':', $recFID);
2230 if ($currentFilesForHistory != $newFiles) {
2231 $this->mmHistoryRecords
[$table . ':' . $id]['oldRecord'][$recFieldName] = $currentFilesForHistory;
2232 $this->mmHistoryRecords
[$table . ':' . $id]['newRecord'][$recFieldName] = $newFiles;
2234 $this->mmHistoryRecords
[$table . ':' . $id]['oldRecord'][$recFieldName] = '';
2235 $this->mmHistoryRecords
[$table . ':' . $id]['newRecord'][$recFieldName] = '';
2238 $this->dbAnalysisStore
[] = array($dbAnalysis, $tcaFieldConf['MM'], $id, 0);
2240 $valueArray = $dbAnalysis->countItems();
2243 if (!empty($valueArray)) {
2244 // If filehandling should NOT be bypassed, do processing:
2245 if (!$this->bypassFileHandling
) {
2247 $propArr = $this->getRecordProperties($table, $id);
2248 foreach ($valueArray as &$theFile) {
2249 // FAL handling: it's a UID, thus it is resolved to the absolute path
2250 if (!empty($theFile) && MathUtility
::canBeInterpretedAsInteger($theFile)) {
2251 $fileObject = ResourceFactory
::getInstance()->getFileObject($theFile);
2252 $theFile = $fileObject->getForLocalProcessing(false);
2254 if ($this->alternativeFilePath
[$theFile]) {
2255 // If alternative File Path is set for the file, then it was an import
2256 // don't import the file if it already exists
2257 if (@is_file
((PATH_site
. $this->alternativeFilePath
[$theFile]))) {
2258 $theFile = PATH_site
. $this->alternativeFilePath
[$theFile];
2259 } elseif (@is_file
($theFile)) {
2260 $dest = dirname(PATH_site
. $this->alternativeFilePath
[$theFile]);
2261 if (!@is_dir
($dest)) {
2262 GeneralUtility
::mkdir_deep(PATH_site
, dirname($this->alternativeFilePath
[$theFile]) . '/');
2265 $maxSize = (int)$tcaFieldConf['max_size'];
2266 // Must be cleared. Else a faulty fileref may be inserted if the below code returns an error!
2268 $fileSize = filesize($theFile);
2270 if (!$maxSize ||
$fileSize <= $maxSize * 1024) {
2271 // Prepare filename:
2272 $theEndFileName = isset($this->alternativeFileName
[$theFile]) ?
$this->alternativeFileName
[$theFile] : $theFile;
2273 $fI = GeneralUtility
::split_fileref($theEndFileName);
2274 // Check for allowed extension:
2275 if ($this->fileFunc
->checkIfAllowed($fI['fileext'], $dest, $theEndFileName)) {
2276 $theDestFile = PATH_site
. $this->alternativeFilePath
[$theFile];
2279 GeneralUtility
::upload_copy_move($theFile, $theDestFile);
2280 $this->copiedFileMap
[$theFile] = $theDestFile;
2282 if ($this->enableLogging
&& !@is_file
($theDestFile)) {
2283 $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, array($theFile, dirname($theDestFile), $recFID), $propArr['event_pid']);
2285 } elseif ($this->enableLogging
) {
2286 $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: No destination file (%s) possible!. (%s)', 11, array($theFile, $theDestFile, $recFID), $propArr['event_pid']);
2288 } elseif ($this->enableLogging
) {
2289 $this->log($table, $id, 5, 0, 1, 'File extension \'%s\' not allowed. (%s)', 12, array($fI['fileext'], $recFID), $propArr['event_pid']);
2291 } elseif ($this->enableLogging
) {
2292 $this->log($table, $id, 5, 0, 1, 'Filesize (%s) of file \'%s\' exceeds limit (%s). (%s)', 13, array(GeneralUtility
::formatSize($fileSize), $theFile, GeneralUtility
::formatSize($maxSize * 1024), $recFID), $propArr['event_pid']);
2294 // If the destination file was created, we will set the new filename in the value array, otherwise unset the entry in the value array!
2295 if (@is_file
($theDestFile)) {
2296 // The value is set to the new filename
2297 $theFile = $theDestFile;
2299 // The value is set to the new filename
2304 if (!empty($theFile)) {
2305 $theFile = GeneralUtility
::fixWindowsFilePath($theFile);
2306 if (GeneralUtility
::isFirstPartOfStr($theFile, PATH_site
)) {
2307 $theFile = PathUtility
::stripPathSitePrefix($theFile);
2319 * Evaluates 'flex' type values.
2321 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
2322 * @param string|array $value The value to set.
2323 * @param array $tcaFieldConf Field configuration from TCA
2324 * @param string $table Table name
2325 * @param int $id UID of record
2326 * @param mixed $curValue Current value of the field
2327 * @param string $status 'update' or 'new' flag
2328 * @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.
2329 * @param string $recFID Field identifier [table:uid:field] for flexforms
2330 * @param int $tscPID TSconfig PID
2331 * @param array $uploadedFiles Uploaded files for the field
2332 * @param string $field Field name
2333 * @return array Modified $res array
2335 protected function checkValueForFlex($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $realPid, $recFID, $tscPID, $uploadedFiles, $field)
2337 if (is_array($value)) {
2338 // This value is necessary for flex form processing to happen on flexform fields in page records when they are copied.
2339 // Problem: when copying a page, flexform XML comes along in the array for the new record - but since $this->checkValue_currentRecord does not have a uid or pid for that
2340 // sake, the BackendUtility::getFlexFormDS() function returns no good DS. For new records we do know the expected PID so therefore we send that with this special parameter.
2341 // Only active when larger than zero.
2342 $newRecordPidValue = $status == 'new' ?
$realPid : 0;
2343 // Get current value array:
2344 $dataStructArray = BackendUtility
::getFlexFormDS($tcaFieldConf, $this->checkValue_currentRecord
, $table, $field, true, $newRecordPidValue);
2345 $currentValueArray = (string)$curValue !== '' ? GeneralUtility
::xml2array($curValue) : array();
2346 if (!is_array($currentValueArray)) {
2347 $currentValueArray = array();
2349 // Remove all old meta for languages...
2350 // Evaluation of input values:
2351 $value['data'] = $this->checkValue_flex_procInData($value['data'], $currentValueArray['data'], $uploadedFiles['data'], $dataStructArray, array($table, $id, $curValue, $status, $realPid, $recFID, $tscPID));
2352 // Create XML from input value:
2353 $xmlValue = $this->checkValue_flexArray2Xml($value, true);
2355 // 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
2356 // (provided that the current value was already stored IN the charset that the new value is converted to).
2357 $arrValue = GeneralUtility
::xml2array($xmlValue);
2359 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkFlexFormValue'])) {
2360 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkFlexFormValue'] as $classRef) {
2361 $hookObject = GeneralUtility
::getUserObj($classRef);
2362 if (method_exists($hookObject, 'checkFlexFormValue_beforeMerge')) {
2363 $hookObject->checkFlexFormValue_beforeMerge($this, $currentValueArray, $arrValue);
2368 ArrayUtility
::mergeRecursiveWithOverrule($currentValueArray, $arrValue);
2369 $xmlValue = $this->checkValue_flexArray2Xml($currentValueArray, true);
2371 // Action commands (sorting order and removals of elements) for flexform sections,
2372 // see FormEngine for the use of this GP parameter
2373 $actionCMDs = GeneralUtility
::_GP('_ACTION_FLEX_FORMdata');
2374 if (is_array($actionCMDs[$table][$id][$field]['data'])) {
2375 $arrValue = GeneralUtility
::xml2array($xmlValue);
2376 $this->_ACTION_FLEX_FORMdata($arrValue['data'], $actionCMDs[$table][$id][$field]['data']);
2377 $xmlValue = $this->checkValue_flexArray2Xml($arrValue, true);
2379 // Create the value XML:
2381 $res['value'] .= $xmlValue;
2384 $res['value'] = $value;
2391 * Converts an array to FlexForm XML
2393 * @param array $array Array with FlexForm data
2394 * @param bool $addPrologue If set, the XML prologue is returned as well.
2395 * @return string Input array converted to XML
2397 public function checkValue_flexArray2Xml($array, $addPrologue = false)
2399 /** @var $flexObj FlexFormTools */
2400 $flexObj = GeneralUtility
::makeInstance(FlexFormTools
::class);
2401 return $flexObj->flexArray2Xml($array, $addPrologue);
2405 * Actions for flex form element (move, delete)
2406 * allows to remove and move flexform sections
2408 * @param array $valueArray by reference
2409 * @param array $actionCMDs
2411 protected function _ACTION_FLEX_FORMdata(&$valueArray, $actionCMDs)
2413 if (!is_array($valueArray) ||
!is_array($actionCMDs)) {
2417 foreach ($actionCMDs as $key => $value) {
2418 if ($key == '_ACTION') {
2419 // First, check if there are "commands":
2420 if (current($actionCMDs[$key]) === '') {
2424 asort($actionCMDs[$key]);
2425 $newValueArray = array();
2426 foreach ($actionCMDs[$key] as $idx => $order) {
2427 if (substr($idx, 0, 3) == 'ID-') {
2428 $idx = $this->newIndexMap
[$idx];
2430 // Just one reflection here: It is clear that when removing elements from a flexform, then we will get lost files unless we act on this delete operation by traversing and deleting files that were referred to.
2431 if ($order != 'DELETE') {
2432 $newValueArray[$idx] = $valueArray[$idx];
2434 unset($valueArray[$idx]);
2436 $valueArray = $valueArray +
$newValueArray;
2437 } elseif (is_array($actionCMDs[$key]) && isset($valueArray[$key])) {
2438 $this->_ACTION_FLEX_FORMdata($valueArray[$key], $actionCMDs[$key]);
2444 * Evaluates 'inline' type values.
2445 * (partly copied from the select_group function on this issue)
2447 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
2448 * @param string $value The value to set.
2449 * @param array $tcaFieldConf Field configuration from TCA
2450 * @param array $PP Additional parameters in a numeric array: $table,$id,$curValue,$status,$realPid,$recFID
2451 * @param string $field Field name
2452 * @param array $additionalData Additional data to be forwarded to sub-processors
2453 * @return array Modified $res array
2455 public function checkValue_inline($res, $value, $tcaFieldConf, $PP, $field, array $additionalData = null)
2457 list($table, $id, , $status) = $PP;
2458 $this->checkValueForInline($res, $value, $tcaFieldConf, $table, $id, $status, $field, $additionalData);
2462 * Evaluates 'inline' type values.
2463 * (partly copied from the select_group function on this issue)
2465 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
2466 * @param string $value The value to set.
2467 * @param array $tcaFieldConf Field configuration from TCA
2468 * @param string $table Table name
2469 * @param int $id UID of record
2470 * @param string $status 'update' or 'new' flag
2471 * @param string $field Field name
2472 * @param array $additionalData Additional data to be forwarded to sub-processors
2473 * @return array Modified $res array
2475 public function checkValueForInline($res, $value, $tcaFieldConf, $table, $id, $status, $field, array $additionalData = null)
2477 if (!$tcaFieldConf['foreign_table']) {
2478 // Fatal error, inline fields should always have a foreign_table defined
2481 // When values are sent they come as comma-separated values which are exploded by this function:
2482 $valueArray = GeneralUtility
::trimExplode(',', $value);
2483 // Remove duplicates: (should not be needed)
2484 $valueArray = array_unique($valueArray);
2485 // Example for received data:
2486 // $value = 45,NEW4555fdf59d154,12,123
2487 // We need to decide whether we use the stack or can save the relation directly.
2488 if (strpos($value, 'NEW') !== false ||
!MathUtility
::canBeInterpretedAsInteger($id)) {
2489 $this->remapStackRecords
[$table][$id] = array('remapStackIndex' => count($this->remapStack
));
2490 $this->addNewValuesToRemapStackChildIds($valueArray);
2491 $this->remapStack
[] = array(
2492 'func' => 'checkValue_inline_processDBdata',
2493 'args' => array($valueArray, $tcaFieldConf, $id, $status, $table, $field, $additionalData),
2494 'pos' => array('valueArray' => 0, 'tcaFieldConf' => 1, 'id' => 2, 'table' => 4),
2495 'additionalData' => $additionalData,
2498 unset($res['value']);
2499 } elseif ($value || MathUtility
::canBeInterpretedAsInteger($id)) {
2500 $res['value'] = $this->checkValue_inline_processDBdata($valueArray, $tcaFieldConf, $id, $status, $table, $field, $additionalData);
2506 * Checks if a fields has more items than defined via TCA in maxitems.
2507 * If there are more items than allowd, the item list is truncated to the defined number.
2509 * @param array $tcaFieldConf Field configuration from TCA
2510 * @param array $valueArray Current value array of items
2511 * @return array The truncated value array of items
2513 public function checkValue_checkMax($tcaFieldConf, $valueArray)
2515 // BTW, checking for min and max items here does NOT make any sense when MM is used because the above function calls will just return an array with a single item (the count) if MM is used... Why didn't I perform the check before? Probably because we could not evaluate the validity of record uids etc... Hmm...
2516 $valueArrayC = count($valueArray);
2517 // NOTE to the comment: It's not really possible to check for too few items, because you must then determine first, if the field is actual used regarding the CType.
2518 $maxI = isset($tcaFieldConf['maxitems']) ?
(int)$tcaFieldConf['maxitems'] : 1;
2519 if ($valueArrayC > $maxI) {
2520 $valueArrayC = $maxI;
2522 // Checking for not too many elements
2523 // Dumping array to list
2525 foreach ($valueArray as $nextVal) {
2526 if ($valueArrayC == 0) {
2530 $newVal[] = $nextVal;
2535 /*********************************************
2537 * Helper functions for evaluation functions.
2539 ********************************************/
2541 * Gets a unique value for $table/$id/$field based on $value
2543 * @param string $table Table name
2544 * @param string $field Field name for which $value must be unique
2545 * @param string $value Value string.
2546 * @param int $id UID to filter out in the lookup (the record itself...)
2547 * @param int $newPid If set, the value will be unique for this PID
2548 * @return string Modified value (if not-unique). Will be the value appended with a number (until 100, then the function just breaks).
2550 public function getUnique($table, $field, $value, $id, $newPid = 0)
2556 $whereAdd .= ' AND pid=' . (int)$newPid;
2558 $whereAdd .= ' AND pid>=0';
2560 // "AND pid>=0" for versioning
2561 $whereAdd .= $this->deleteClause($table);
2562 // If the field is configured in TCA, proceed:
2563 if (is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['columns'][$field])) {
2564 // Look for a record which might already have the value:
2565 $res = $this->databaseConnection
->exec_SELECTquery('uid', $table, $field . '=' . $this->databaseConnection
->fullQuoteStr($value, $table) . ' AND uid<>' . (int)$id . $whereAdd);
2567 // For as long as records with the test-value existing, try again (with incremented numbers appended).
2568 while ($this->databaseConnection
->sql_num_rows($res)) {
2569 $newValue = $value . $counter;
2570 $res = $this->databaseConnection
->exec_SELECTquery('uid', $table, $field . '=' . $this->databaseConnection
->fullQuoteStr($newValue, $table) . ' AND uid<>' . (int)$id . $whereAdd);
2572 if ($counter > 100) {
2576 $this->databaseConnection
->sql_free_result($res);
2577 // If the new value is there:
2578 $value = $newValue !== '' ?
$newValue : $value;
2584 * gets all records that have the same value in a field
2585 * excluding the given uid
2587 * @param string $tableName Table name
2588 * @param int $uid UID to filter out in the lookup (the record itself...)
2589 * @param string $fieldName Field name for which $value must be unique
2590 * @param string $value Value string.
2591 * @param int $pageId If set, the value will be unique for this PID
2594 public function getRecordsWithSameValue($tableName, $uid, $fieldName, $value, $pageId = 0)
2597 if (!empty($GLOBALS['TCA'][$tableName]['columns'][$fieldName])) {
2599 $pageId = (int)$pageId;
2600 $whereStatement = ' AND uid <> ' . $uid . ' AND ' . ($pageId ?
'pid = ' . $pageId : 'pid >= 0');
2601 $result = BackendUtility
::getRecordsByField($tableName, $fieldName, $value, $whereStatement);
2607 * @param string $value The field value to be evaluated
2608 * @param array $evalArray Array of evaluations to traverse.
2609 * @param string $is_in The "is_in" value of the field configuration from TCA
2612 public function checkValue_text_Eval($value, $evalArray, $is_in)
2616 foreach ($evalArray as $func) {
2619 $value = trim($value);
2627 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
2628 if (class_exists($func)) {
2629 $evalObj = GeneralUtility
::makeInstance($func);
2630 if (method_exists($evalObj, 'evaluateFieldValue')) {
2631 $value = $evalObj->evaluateFieldValue($value, $is_in, $set);
2638 $res['value'] = $value;
2644 * Evaluation of 'input'-type values based on 'eval' list
2646 * @param string $value Value to evaluate
2647 * @param array $evalArray Array of evaluations to traverse.
2648 * @param string $is_in Is-in string for 'is_in' evaluation
2649 * @return array Modified $value in key 'value' or empty array
2651 public function checkValue_input_Eval($value, $evalArray, $is_in)
2655 foreach ($evalArray as $func) {
2661 $value = (int)$value;
2665 $value = (int)$value;
2666 if ($value > 0 && !$this->dontProcessTransformations
) {
2667 $value -= date('Z', $value);
2671 $value = preg_replace('/[^0-9,\\.-]/', '', $value);
2672 $negative = $value[0] === '-';
2673 $value = strtr($value, array(',' => '.', '-' => ''));
2674 if (strpos($value, '.') === false) {
2677 $valueArray = explode('.', $value);
2678 $dec = array_pop($valueArray);
2679 $value = join('', $valueArray) . '.' . $dec;
2683 $value = number_format($value, 2, '.', '');
2686 if (strlen($value) != 32) {
2691 $value = trim($value);
2694 /** @var CharsetConverter $charsetConverter */
2695 $charsetConverter = GeneralUtility
::makeInstance(CharsetConverter
::class);
2696 $value = $charsetConverter->conv_case('utf-8', $value, 'toUpper');
2699 /** @var CharsetConverter $charsetConverter */
2700 $charsetConverter = GeneralUtility
::makeInstance(CharsetConverter
::class);
2701 $value = $charsetConverter->conv_case('utf-8', $value, 'toLower');
2704 if (!isset($value) ||
$value === '') {
2709 $c = strlen($value);
2712 for ($a = 0; $a < $c; $a++
) {
2713 $char = substr($value, $a, 1);
2714 if (strpos($is_in, $char) !== false) {
2722 $value = str_replace(' ', '', $value);
2725 $value = preg_replace('/[^a-zA-Z]/', '', $value);
2728 $value = preg_replace('/[^0-9]/', '', $value);
2731 $value = preg_replace('/[^a-zA-Z0-9]/', '', $value);
2734 $value = preg_replace('/[^a-zA-Z0-9_-]/', '', $value);
2737 if (!preg_match('/^[a-z0-9.\\-]*$/i', $value)) {
2738 $value = GeneralUtility
::idnaEncode($value);
2742 if ((string)$value !== '') {
2743 $this->checkValue_input_ValidateEmail($value, $set);
2747 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func])) {
2748 if (class_exists($func)) {
2749 $evalObj = GeneralUtility
::makeInstance($func);
2750 if (method_exists($evalObj, 'evaluateFieldValue')) {
2751 $value = $evalObj->evaluateFieldValue($value, $is_in, $set);
2758 $res['value'] = $value;
2764 * If $value is not a valid e-mail address,
2765 * $set will be set to false and a flash error
2766 * message will be added
2768 * @param string $value Value to evaluate
2769 * @param bool $set TRUE if an update should be done
2770 * @throws \InvalidArgumentException
2771 * @throws \TYPO3\CMS\Core\Exception
2774 protected function checkValue_input_ValidateEmail($value, &$set)
2776 if (GeneralUtility
::validEmail($value)) {
2781 /** @var FlashMessage $message */
2782 $message = GeneralUtility
::makeInstance(FlashMessage
::class,
2783 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:error.invalidEmail'), $value),
2784 '', // header is optional
2785 FlashMessage
::ERROR
,
2786 true // whether message should be stored in session
2788 /** @var $flashMessageService FlashMessageService */
2789 $flashMessageService = GeneralUtility
::makeInstance(FlashMessageService
::class);
2790 $flashMessageService->getMessageQueueByIdentifier()->enqueue($message);
2794 * Returns data for group/db and select fields
2796 * @param array $valueArray Current value array
2797 * @param array $tcaFieldConf TCA field config
2798 * @param int $id Record id, used for look-up of MM relations (local_uid)
2799 * @param string $status Status string ('update' or 'new')
2800 * @param string $type The type, either 'select', 'group' or 'inline'
2801 * @param string $currentTable Table name, needs to be passed to \TYPO3\CMS\Core\Database\RelationHandler
2802 * @param string $currentField field name, needs to be set for writing to sys_history
2803 * @return array Modified value array
2805 public function checkValue_group_select_processDBdata($valueArray, $tcaFieldConf, $id, $status, $type, $currentTable, $currentField)
2807 $tables = $type == 'group' ?
$tcaFieldConf['allowed'] : $tcaFieldConf['foreign_table'];
2808 $prep = $type == 'group' ?
$tcaFieldConf['prepend_tname'] : '';
2809 $newRelations = implode(',', $valueArray);
2810 /** @var $dbAnalysis RelationHandler */
2811 $dbAnalysis = $this->createRelationHandlerInstance();
2812 $dbAnalysis->registerNonTableValues
= !empty($tcaFieldConf['allowNonIdValues']);
2813 $dbAnalysis->start($newRelations, $tables, '', 0, $currentTable, $tcaFieldConf);
2814 if ($tcaFieldConf['MM']) {
2815 if ($status == 'update') {
2816 /** @var $oldRelations_dbAnalysis RelationHandler */
2817 $oldRelations_dbAnalysis = $this->createRelationHandlerInstance();
2818 $oldRelations_dbAnalysis->registerNonTableValues
= !empty($tcaFieldConf['allowNonIdValues']);
2819 // Db analysis with $id will initialize with the existing relations
2820 $oldRelations_dbAnalysis->start('', $tables, $tcaFieldConf['MM'], $id, $currentTable, $tcaFieldConf);
2821 $oldRelations = implode(',', $oldRelations_dbAnalysis->getValueArray());
2822 $dbAnalysis->writeMM($tcaFieldConf['MM'], $id, $prep);
2823 if ($oldRelations != $newRelations) {
2824 $this->mmHistoryRecords
[$currentTable . ':' . $id]['oldRecord'][$currentField] = $oldRelations;
2825 $this->mmHistoryRecords
[$currentTable . ':' . $id]['newRecord'][$currentField] = $newRelations;
2827 $this->mmHistoryRecords
[$currentTable . ':' . $id]['oldRecord'][$currentField] = '';
2828 $this->mmHistoryRecords
[$currentTable . ':' . $id]['newRecord'][$currentField] = '';
2831 $this->dbAnalysisStore
[] = array($dbAnalysis, $tcaFieldConf['MM'], $id, $prep, $currentTable);
2833 $valueArray = $dbAnalysis->countItems();
2835 $valueArray = $dbAnalysis->getValueArray($prep);
2837 // Here we should see if 1) the records exist anymore, 2) which are new and check if the BE_USER has read-access to the new ones.
2842 * Explodes the $value, which is a list of files/uids (group select)
2844 * @param string $value Input string, comma separated values. For each part it will also be detected if a '|' is found and the first part will then be used if that is the case. Further the value will be rawurldecoded.
2845 * @return array The value array.
2847 public function checkValue_group_select_explodeSelectGroupValue($value)
2849 $valueArray = GeneralUtility
::trimExplode(',', $value, true);
2850 foreach ($valueArray as &$newVal) {
2851 $temp = explode('|', $newVal, 2);
2852 $newVal = str_replace(',', '', str_replace('|', '', rawurldecode($temp[0])));
2859 * Starts the processing the inp