Get tt_content uid
Asked Answered
C

5

6

I am developing an extension that allows admins to save stuff to the database.

And I want that each instance of the extension should have it's own Id in the database. Is there some way to get the tt_content uid (which I guess is the extension instance Id) in the extension php.

Choose answered 4/5, 2012 at 11:31 Comment(1)
You are mixing up the terminology here. An extension does not have an id. An extension is a specific package in TYPO3 which usually resides in typo3conf/ext or typo3/sysext. What you probably mean is "plugin" or "content element". I would recommend to clean up the question.Ramses
N
13

You fetch all tt_content's data in array:

$this->cObj->data

ie:

$uidOfCE = $this->cObj->data['uid'];

If you're using Extbase of course you need to get the content object first, ie:

$this->contentObj = $this->configurationManager->getContentObject();
debug($this->contentObj->data, "current tt_content's data");
Naevus answered 4/5, 2012 at 11:54 Comment(1)
Also how can we get content id in Typoscript like for eg. <div class="module" id="<need content ID here>">Fluctuation
E
2

Here is the way (Tested in TYPO3 9.5.4 & 10.4.3)

Get current content id inside controller

$this->configurationManager->getContentObject()->data['uid'];

AND

This will return whole HTML of content which you can render directly

$conf = [
    'tables' => 'tt_content',
    'source' => $uid, //uid of tt_content
    'dontCheckPid' => 1
];
$html = $GLOBALS['TSFE']->cObj->cObjGetSingle('RECORDS', $conf);
Expellant answered 13/2, 2019 at 5:29 Comment(0)
N
1

Since TYPO3 v12.4, configurationManager->getContentObject() is deprecated.

The new correct way is this:

$uid = $request->getAttribute('currentContentObject')->data['uid'];
Nadler answered 26/1 at 7:58 Comment(0)
C
0

$contentId is content id in typo3 backend

$content_rec = $GLOBALS["TYPO3_DB"]->exec_SELECTgetrows('header,bodytext','tt_content','uid='.$contentId);
$this->markerArray['###content###'] = $content_rec[0]['bodytext'];
Cudgel answered 2/12, 2013 at 8:10 Comment(0)
G
0

For the effects of update that answer and know an plugin uid, you could debug \TYPO3\CMS\Core\Utility\DebugUtility::debug($this->configurationManager->getContentObject()->data['uid'], 'parameter');

If is not complete the debug does not show the uid because configurationManager and contentObject use lazy loading.

This works and tested from TYPO3 8.7

Gannet answered 28/6, 2019 at 13:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.