问题
When creating new database records, TYPO3 assigns them a temporary UID, which looks like this: NEW56fe740dd5a455.64167468
. The record gets its real UID when it is inserted into the database.
In the above hook, the record is already inserted into the database, so it has a numerical uid assigned. How do I get that uid from a given temporary UID?
回答1:
Ok, found it. The fourth parameter of the hook-method is the datahandler object, which has a property substNEWwithIDs
, an associative array mapping temporary UIDs to the real UIDs.
One can use it like this:
public function processDatamap_afterDatabaseOperations($action, $table, $uid, $datahandler)
{
if (GeneralUtility::isFirstPartOfStr($uid, 'NEW')) {
$uid = $datahandler->substNEWwithIDs[$uid];
}
// Do something with the UID
}
来源:https://stackoverflow.com/questions/36357502/get-uid-of-new-record-in-hook-processdatamap-afterdatabaseoperations