public function setDefaultFieldValues(array &$fieldArray, $uidPid = 0)
    {
        // Default values:
        $newRow = []; // Used to store default values as found here:

        // Default values as set in userTS:
        $TCAdefaultOverride = (array)($this->getBackendUser()->getTSConfig()['TCAdefaults'] ?? []);
        if (is_array($TCAdefaultOverride['tt_content.'])) {
            foreach ($TCAdefaultOverride['tt_content.'] as $field => $value) {
                if (isset($GLOBALS['TCA']['tt_content']['columns'][$field])) {
                    $newRow[$field] = $value;
                }
            }
        }

        if ($uidPid < 0) {
            $record = BackendUtility::getRecord('tt_content', abs($uidPid), 'pid');
            $pageId = $record['pid'];
        } else {
            $pageId = (int)$uidPid;
        }

        $pageTS = BackendUtility::getPagesTSconfig($pageId);

        if (isset($pageTS['TCAdefaults.'])) {
            $TCAPageTSOverride = $pageTS['TCAdefaults.'];
            if (is_array($TCAPageTSOverride['tt_content.'])) {
                foreach ($TCAPageTSOverride['tt_content.'] as $field => $value) {
                    if (isset($GLOBALS['TCA']['tt_content']['columns'][$field])) {
                        $newRow[$field] = $value;
                    }
                }
            }
        }

        // Default values as submitted:
        $this->definitionValues = GeneralUtility::_GP('defVals');
        $this->overrideValues = GeneralUtility::_GP('overrideVals');
        if (!is_array($this->definitionValues) && is_array($this->overrideValues)) {
            $this->definitionValues = $this->overrideValues;
        }
        if (is_array($this->definitionValues['tt_content'])) {
            foreach ($this->definitionValues['tt_content'] as $field => $value) {
                if (isset($GLOBALS['TCA']['tt_content']['columns'][$field])) {
                    $newRow[$field] = $value;
                }
            }
        }

        // Fetch default values if a previous record exists
        if ($uidPid < 0 && !empty($record) && $GLOBALS['TCA']['tt_content']['ctrl']['useColumnsForDefaultValues']) {
            // Gets the list of fields to copy from the previous record.
            $fieldArray = explode(',', $GLOBALS['TCA']['tt_content']['ctrl']['useColumnsForDefaultValues']);
            foreach ($fieldArray as $field) {
                $field = trim($field);
                if ($field === '') {
                    continue;
                }
                if (isset($GLOBALS['TCA']['tt_content']['columns'][$field])) {
                    $newRow[$field] = $record[$field];
                }
            }
        }
        $fieldArray = array_merge($newRow, $fieldArray);
    }
public function setDefaultFieldValues(array &$fieldArray, $uidPid = 0)
    {
        // Default values:
        $newRow = []; // Used to store default values as found here:

        // Default values as set in userTS:
        $TCAdefaultOverride = (array)($this->getBackendUser()->getTSConfig()['TCAdefaults'] ?? []);
        if (is_array($TCAdefaultOverride['tt_content.'])) {
            foreach ($TCAdefaultOverride['tt_content.'] as $field => $value) {
                if (isset($GLOBALS['TCA']['tt_content']['columns'][$field])) {
                    $newRow[$field] = $value;
                }
            }
        }

        if ($uidPid < 0) {
            $record = BackendUtility::getRecord('tt_content', abs($uidPid), 'pid');
            $pageId = $record['pid'];
        } else {
            $pageId = (int)$uidPid;
        }

        $pageTS = BackendUtility::getPagesTSconfig($pageId);

        if (isset($pageTS['TCAdefaults.'])) {
            $TCAPageTSOverride = $pageTS['TCAdefaults.'];
            if (is_array($TCAPageTSOverride['tt_content.'])) {
                foreach ($TCAPageTSOverride['tt_content.'] as $field => $value) {
                    if (isset($GLOBALS['TCA']['tt_content']['columns'][$field])) {
                        $newRow[$field] = $value;
                    }
                }
            }
        }

        // Default values as submitted:
        $this->definitionValues = GeneralUtility::_GP('defVals');
        $this->overrideValues = GeneralUtility::_GP('overrideVals');
        if (!is_array($this->definitionValues) && is_array($this->overrideValues)) {
            $this->definitionValues = $this->overrideValues;
        }
        if (is_array($this->definitionValues['tt_content'])) {
            foreach ($this->definitionValues['tt_content'] as $field => $value) {
                if (isset($GLOBALS['TCA']['tt_content']['columns'][$field])) {
                    $newRow[$field] = $value;
                }
            }
        }

        // Fetch default values if a previous record exists
        if ($uidPid < 0 && !empty($record) && $GLOBALS['TCA']['tt_content']['ctrl']['useColumnsForDefaultValues']) {
            // Gets the list of fields to copy from the previous record.
            $fieldArray = explode(',', $GLOBALS['TCA']['tt_content']['ctrl']['useColumnsForDefaultValues']);
            foreach ($fieldArray as $field) {
                $field = trim($field);
                if ($field === '') {
                    continue;
                }
                if (isset($GLOBALS['TCA']['tt_content']['columns'][$field])) {
                    $newRow[$field] = $record[$field];
                }
            }
        }
        $fieldArray = array_merge($newRow, $fieldArray);
    }
public function setDefaultFieldValues ( array & $ fieldArray , $ uidPid = 0 ) { // Default values: $ newRow = [ ] ; // Used to store default values as found here: // Default values as set in userTS: $ TCAdefaultOverride = ( array ) ( $ this -> getBackendUser ( ) -> getTSConfig ( ) [ 'TCAdefaults' ] ?? [ ] ) ; if ( is_array ( $ TCAdefaultOverride [ 'tt_content.' ] ) ) { foreach ( $ TCAdefaultOverride [ 'tt_content.' ] as $ field => $ value ) { if ( isset ( $ GLOBALS [ 'TCA' ] [ 'tt_content' ] [ 'columns' ] [ $ field ] ) ) { $ newRow [ $ field ] = $ value ; } } } if ( $ uidPid < 0 ) { $ record = BackendUtility :: getRecord ( 'tt_content' , abs ( $ uidPid ) , 'pid' ) ; $ pageId = $ record [ 'pid' ] ; } else { $ pageId = ( int ) $ uidPid ; } $ pageTS = BackendUtility :: getPagesTSconfig ( $ pageId ) ; if ( isset ( $ pageTS [ 'TCAdefaults.' ] ) ) { $ TCAPageTSOverride = $ pageTS [ 'TCAdefaults.' ] ; if ( is_array ( $ TCAPageTSOverride [ 'tt_content.' ] ) ) { foreach ( $ TCAPageTSOverride [ 'tt_content.' ] as $ field => $ value ) { if ( isset ( $ GLOBALS [ 'TCA' ] [ 'tt_content' ] [ 'columns' ] [ $ field ] ) ) { $ newRow [ $ field ] = $ value ; } } } } // Default values as submitted: $ this -> definitionValues = GeneralUtility :: _GP ( 'defVals' ) ; $ this -> overrideValues = GeneralUtility :: _GP ( 'overrideVals' ) ; if ( ! is_array ( $ this -> definitionValues ) && is_array ( $ this -> overrideValues ) ) { $ this -> definitionValues = $ this -> overrideValues ; } if ( is_array ( $ this -> definitionValues [ 'tt_content' ] ) ) { foreach ( $ this -> definitionValues [ 'tt_content' ] as $ field => $ value ) { if ( isset ( $ GLOBALS [ 'TCA' ] [ 'tt_content' ] [ 'columns' ] [ $ field ] ) ) { $ newRow [ $ field ] = $ value ; } } } // Fetch default values if a previous record exists if ( $ uidPid < 0 && ! empty ( $ record ) && $ GLOBALS [ 'TCA' ] [ 'tt_content' ] [ 'ctrl' ] [ 'useColumnsForDefaultValues' ] ) { // Gets the list of fields to copy from the previous record. $ fieldArray = explode ( ',' , $ GLOBALS [ 'TCA' ] [ 'tt_content' ] [ 'ctrl' ] [ 'useColumnsForDefaultValues' ] ) ; foreach ( $ fieldArray as $ field ) { $ field = trim ( $ field ) ; if ( $ field === '' ) { continue ; } if ( isset ( $ GLOBALS [ 'TCA' ] [ 'tt_content' ] [ 'columns' ] [ $ field ] ) ) { $ newRow [ $ field ] = $ record [ $ field ] ; } } } $ fieldArray = array_merge ( $ newRow , $ fieldArray ) ; }
set default field values for new records

@param array $fieldArray
@param int $uidPid
set default field values for new records