Bug #100970
openin USER / USER_INT the calling CE isn't exposed
0%
Description
While writing a USER / USER_INT class it seems impossible to know which element was called to trigger the execution.
So all elements have to be crawled and likely the register of TSFE be filled with elements that have been processed, but there isn't any way to get a reliable hint about the calling element.
Updated by Oliver Hader about 1 year ago
- Status changed from New to Needs Feedback
Can you please give more context or an example?
Updated by David Bruchmann about 1 year ago
TSFE->cObj is just the page record, so it's not useful here.
An example could be that headline and content of header and bodytext should be available in the class.
So I've to retrieve the fields, which should be in my opinion already available in TSFE->cObj->data.
Never having an uid at least it's not possible to know which record to query.
So it seems to be required to query all applying records and to process them systematically, also using a register property of TSFE, so that a CE isn't processed twice.
Updated by Stefan Bürk about 1 year ago
Not getting this, this should basically works (not tested, but from the code).
In your user function class, you should access to the parent information with:
$parentData = $this->cObj->parentRecord['data'] ?? null;
$parentCurrentRecord = $this->cObj->parentRecord['currentRecord'] ?? null;
If I remember right, you should have a "setContentObjectRenderer()" method
in your user method to as public $cObj setting is deprectated.
UserInt gehts serialized/deserialized but this information should be existing.
And trying to work with TSFE->cObj looks scary. You should more operate on the
current contentObject and the parent.
Maybe you can provide some code what you are trying to solve ?
Updated by David Bruchmann about 1 year ago
the method begins like this
public function start(string $content, array $conf): string { if (!is_object($this->getTsfe())) { return $content; } $cObj = $this->getTsfe()->cObj; $parentData = $cObj->parentRecord['data'] ?? null; $parentCurrentRecord = $cObj->parentRecord['currentRecord'] ?? null; ...
and actually I want to merge TypoScript with json (we chatted about the json, Stefan).
But that's coming afterwards,first I want to get the cObj though.
Updated by David Bruchmann about 1 year ago
Throughout the classes TypoScriptFrontendController and all related classes it's stated that properties are assigned if the record is of type CONTENT or RECORD, but USER / USER int isn't mentioned at all. So actually the behavior is at least consistent to the internal documentation.
Nevertheless it's not sufficient.
Example copied from the code in TypoScriptFrontendController:
/** * This is set to the [table]:[uid] of the latest record rendered. Note that * class ContentObjectRenderer has an equal value, but that is pointing to the * record delivered in the $data-array of the ContentObjectRenderer instance, if * the cObjects CONTENT or RECORD created that instance */ public string $currentRecord = '';
Updated by Stefan Bürk about 1 year ago
Please provide some more context and information. For example, you could
add the used TypoScript as example. Not fully getting what you are trying
to really do here and why the parent record is needed or not.
Would be nice if you could provide something which can be used to reproduce
this easily and debug this in some way. Cannot get your "configuration" used
and hitting this "issue". That would minimize the time to get a reproducable
state locally running instead of trying to reproduce this with a lot of guessing.
So, please provide an example (TypoScript etc) needed to get/reproduce this.
Updated by David Bruchmann about 1 year ago
Hi STefan,
thanks for having a look at it again.
I think the information you ask for is not relevant, I described it already very clear.
The TypoScript is very simple:
asd = USER asd.userFunc = \XYZ\Abc\....
If you think you can't do anything with my descriptions, just close this issue.
I solved it for the moment with a loop and overwriting TSFE myself. It might not be 100% correct but it's working.
Updated by David Bruchmann 9 months ago
· Edited
I added one line (the first one below) and that's solving my case of much headaches, as I've the required data available.
Like this I can access anything that is stored in the CE record.
Without my change it''s almost impossible to determine from which record the call is coming, if several USER elements are on one page.
Class: TYPO3\CMS\Frontend\ContentObject\UserContentObject
$conf['_data_'] = $this->cObj->data; $tempContent = $this->cObj->callUserFunction($conf['userFunc'] ?? '', $conf, '');