Get uid of new record in hook processDatamap_afterDatabaseOperations

限于喜欢 提交于 2019-12-13 15:06:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!