php - Typo3 Plugin Inline Records in Frontend Controller

910

I'm trying to create a Typo3 Extension using extbase and stumbled upon a problem. What I have done so far is this: I created a plugin editable via flexform for the backend. The plugin allows for dynamically changing some fields, so the flexform is using inline records that can be stored successfully in the database in their own table tx_jwfrontendusermanager_editorfields. The pid for the table entries is the same as for the content object they are attached to, and an additional field in the table holds the content object's id. The backend works fine so far, I can create/edit/delete inline records for the content objects without any problem.

Unfortunately, I can't seem to figure out how to access the inline records in the ActionController in the frontend, and I can't find any documentation about how to do so. Could anyone point me into the right direction?

What I have tried so far:

First (primitive) approach: Accessing the flexform inline field like any other field from the form. This just returns the number "7". Obviously it's not meant to be used this way.

Second approach: I created a Model/Repository for the EditorFields table, and mapped the Model class to the table using Typoscript. The mapping itself seems to work fine. Unfortunately, I cannot select just the records that are connected to the current content object. A call to Repository->findAll() returns an empty array. I debugged the SQL query for the findAll command and found out three problems:

  1. The query filters by the tx_jwfrontendusermanager_editorfield.pid field, but using the wrong page id. The pid used is the one I selected in the plugin's 'Record Storage Page' field, not the one of the content object.

  2. The query does not filter for the content object id, but would show all records for all content objects on the page.

  3. The query filters by an additional

    `tx_jwfrontendusermanager_editorfield`.`type` = "\Jw301\JwFrontendusermanager\Domain\Model\EditorField"
    

    Which doesn't make any sense, as none of the records has the type field set to something like this. The type is used by the backend to distinguish between different kinds of records. That way, the query will never have any results.

So, how can this be changed in a way that the Repository finds the correct records? Is this even the right approach?

Third approach: As the Repository approach wasn't successful, I tried to get the records myself by creating a custom SQL query. This works in general, but I still have trouble filtering the right records for me. I can get the current page id easily using

$GLOBALS['TSFE']->page['uid']

But there seems to be no way to get the content object id in the ActionController. I found many Internet sources that said I should use

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

from within the ActionController to access the current content object id, but for me that didn't work. I tried this in every ActionController in my project, yet the uid field was never there. The $cObj I get is of type ContentObjectRenderer, but the data array is always empty.

How can I access the content object uid from within an ActionController?

Thanks for any help or hints that lead me into the right direction.

People are also looking for solutions to the problem: php - Show cgridview data based on condition

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.