StrikeAgainst
StrikeAgainst

Reputation: 634

TYPO3 - how to have backend user as model property?

I've defined a model in my TYPO3 extension where I want one property referring to the backend user who has performed some certain action on it in the backend module. Unfortunately I'm not quite sure how to implement it, since on one side there doesn't seem to be a backend user model class which I can refer to, on the other side defining the TCA referring to the be_users table like this

'respondentUser' => [
    'label' => 'Respondent',
    'config' => [
        'type' => 'select',
        'foreign_table' => 'be_users',
        'maxitems' => 1
    ]
],

only returns objects with an empty user value (with the user UID set by myself). The at first glance more obvious user type didn't turn out to be what I needed either. Is there any support for model-user-relationships at all?

If not, I could work with the user's UID as integer alone. I know that I can get it through $GLOBALS['BE_USERS']->user['uid'], but how would I receive the user data (the username, to be accurate) from an UID?

Upvotes: 0

Views: 374

Answers (1)

Jonas Eberle
Jonas Eberle

Reputation: 2921

Check your TCA https://docs.typo3.org/m/typo3/reference-tca/9.5/en-us/ColumnsConfig/Type/Select.html - for type:select a renderType is mandatory.

Regarding your wish for a BackendUser model: there is \TYPO3\CMS\Extbase\Domain\Model\BackendUser (and its \TYPO3\CMS\Extbase\Domain\Repository\BackendUserRepository). So you can just get away with defining your model property respondentUser as \TYPO3\CMS\Extbase\Domain\Model\BackendUser and your Extbase repository will do the data-knitting.

For the domain modeling evangelists you should reimplement it in your domain and check out the table <> Extbase class mapping here: https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/6-Persistence/5-modeling-the-class-hierarchy.html. If you go that road, check out https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ExtensionArchitecture/FilesAndLocations/Index.html#ext-typoscript-setup-typoscript and mind that ext_typoscript_setup has deficits. I would use \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptSetup().

That said, there is absolutely no obligation to use Extbase in TYPO3. You can fetch the be_user record from your be_user.uid with https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Database/QueryBuilder/Index.html to get a raw record. Most often that is just enough to work with it.

Upvotes: 1

Related Questions