Project

General

Profile

Actions

Bug #100970

open

in USER / USER_INT the calling CE isn't exposed

Added by David Bruchmann 11 months ago. Updated 5 months ago.

Status:
Needs Feedback
Priority:
Should have
Assignee:
-
Category:
Content Rendering
Target version:
-
Start date:
2023-06-07
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
12
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

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.

Actions #1

Updated by Oliver Hader 11 months ago

  • Status changed from New to Needs Feedback

Can you please give more context or an example?

Actions #2

Updated by David Bruchmann 11 months 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.

Actions #3

Updated by Stefan Bürk 11 months 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 ?

Actions #4

Updated by David Bruchmann 11 months ago

$cObj->parentRecord is empty

Actions #5

Updated by David Bruchmann 11 months 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.

Actions #6

Updated by David Bruchmann 11 months 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 = '';

Actions #7

Updated by Stefan Bürk 11 months 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.

Actions #8

Updated by David Bruchmann 11 months 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.

Actions #9

Updated by David Bruchmann 5 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, '');
Actions

Also available in: Atom PDF