i would like to show the user who created an element. The TCA looks like this:
'ctrl' => [
'title' => 'Title',
'label' => 'title',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
With getter i can get the tstamp and the crdate. But with the cruser_id this doesn't work. How can i get the user name of the user with the cruser_id?
The following example, works on TYPO3 11.5.8 and should work with TYPO3 10 as well.
First you need your getters und setters on your model (\YourVendor\YourExtension\Domain\Model\YourModel)
/**
* #var int
*/
protected int $cruserId = 0;
/**
* #return int
*/
public function getCruserId(): int
{
return $this->cruserId;
}
/**
* #param int $cruserId
*/
public function setCruserId(int $cruserId): void
{
$this->cruserId = $cruserId;
}
Then you need to add the TCA configuration for this specific field. You do not need to add it on types or anywhere else. TYPO3 just needs the configuration so it knows what to do with it.
'cruser_id' => [
'config' => [
'type' => 'input',
'size' => 10,
'max' => 255,
],
],
Last and not least, you need to map it on the right column. So under your your_extension/Configuration/Extbase/Persistence/Classes.php you need to add your Model and the property:
\YourVendor\YourExtension\Domain\Model\YourModel::class => [
'columns' => [
'cruserId' => [
'mapOnProperty' => 'cruser_id'
]
]
]
Here is a reference: TYPO3 v10 How do i get an object's crdate or the tstamp in FrontEnd
Backend User Object
If you want to get the Backend user information, the steps are the same but some changes need to be made.
Model
use TYPO3\CMS\Beuser\Domain\Model\BackendUser
/**
* #var BackendUser|null
*/
protected ?BackendUser $cruserId = null;
/**
* #return BackendUser|null
*/
public function getCruserId(): ?BackendUser
{
return $this->cruserId;
}
/**
* #param ?BackendUser $cruserId
*/
public function setCruserId(?BackendUser $cruserId): void
{
$this->cruserId = $cruserId;
}
TCA
'cruser_id' => [
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'foreign_table' => 'be_users',
'foreign_table_where' => 'ORDER BY username',
],
],
This will give you the following:
Hope it helped
I have a typo3 extension which allows to create Content Elements within the extension - in typo3 v9 it works fine but on typo3 v10 it doesn’t, when I debug in the template i got this result:
contentElements => protected TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorageprototypeobject (empty)
The Content Element is created and in the backend also correctly visible within the Dataset
I also tried to have a look at tx_news which implements a simular behaiver but I doesn’t have a clue, for me it seems that I done right but yeah … , following some code snippets I used, may you have an Idea:
In the setup.typoscript:
lib.contenttabs_fecontenttabs.contentElementRendering = RECORDS
lib.contenttabs_fecontenttabs.contentElementRendering {
tables = tt_content
source.current = 1
dontCheckPid = 1
}
In the Model (I tried to use the sam as news):
/**
* Get content elements
*
* #return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
*/
public function getContentElements()
{
return $this->contentElements;
}
/**
* Set content element list
*
* #param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $contentElements content elements
*/
public function setContentElements($contentElements)
{
$this->contentElements = $contentElements;
}
/**
* Adds a content element to the record
*
* #param \Moc\Contenttabs\Domain\Model\TtContent $contentElement
*/
public function addContentElement(\Moc\Contenttabs\Domain\Model\TtContent $contentElement)
{
if ($this->getContentElements() === null) {
$this->contentElements = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
$this->contentElements->attach($contentElement);
}
/**
* Get id list of content elements
*
* #return string
*/
public function getContentElementIdList()
{
return $this->getIdOfContentElements();
}
/**
* Get translated id list of content elements
*
* #return string
*/
public function getTranslatedContentElementIdList()
{
return $this->getIdOfContentElements(false);
}
/**
* Collect id list
*
* #param bool $original
* #return string
*/
protected function getIdOfContentElements($original = true)
{
$idList = [];
$contentElements = $this->getContentElements();
if ($contentElements) {
foreach ($this->getContentElements() as $contentElement) {
if ($contentElement->getColPos() >= 0) {
$idList[] = $original ? $contentElement->getUid() : $contentElement->_getProperty('_localizedUid');
}
}
}
return implode(',', $idList);
}
In the Template:
<f:cObject typoscriptObjectPath="lib.contenttabs_fecontenttabs.contentElementRendering">
{tab.contentElementIdList}
</f:cObject>
Some of the TCA Code (which seems to works fine):
'content_elements' => [
'exclude' => 1,
'l10n_mode' => 'mergeIfNotBlank',
'label' => 'Content Elements',
'config' => [
'type' => 'inline',
'allowed' => 'tt_content',
'foreign_table' => 'tt_content',
'foreign_sortby' => 'sorting',
'foreign_field' => 'tx_tabs_content_elements',
'minitems' => 0,
'maxitems' => 99,
'overrideChildTca' => [
'columns' => [
'colPos' => [
'config' => [
'default' => 99
]
],
'CType' => [
'config' => [
'default' => 'textmedia'
]
]
]
],
'appearance' => [
'collapseAll' => 1,
'expandSingle' => 1,
'levelLinksPosition' => 'bottom',
'useSortable' => 1,
'showPossibleLocalizationRecords' => 1,
'showRemovedLocalizationRecords' => 1,
'showAllLocalizationLink' => 1,
'showSynchronizationLink' => 1,
'enabledControls' => [
'info' => false,
]
]
]
],
Thanks in advance!
I have TYPO3 7.6.18, and I have problem with query.
this works
public function getFiltered($offset = 0, $limit = 5){
$query = $this->createQuery();
$query->matching($query->equals('cruserId', 3));
return $query->execute();
But this not works
public function getFiltered($offset = 0, $limit = 5){
$query = $this->createQuery();
$query->matching($query->equals('cruserId.uid', 3));
return $query->execute();
this return empty. Why? I filter by condition in another table(fe_users). I need filter by uid, gender or other fields. I don't know where is a problem.
TCA:
'cruser_id' => [
'exclude' => 1,
'label' => 'LLL:EXT:fefiles/Resources/Private/Language/locallang_db.xlf:tx_fefiles_domain_model_photo.cruser_id',
'config' => [
'type' => 'inline',
'foreign_table' => 'fe_users',
'minitems' => 0,
'maxitems' => 1,
'appearance' => [
'collapseAll' => 0,
'levelLinksPosition' => 'top',
'showSynchronizationLink' => 1,
'showPossibleLocalizationRecords' => 1,
'showAllLocalizationLink' => 1
],
]
],
Model:
/**
* CruserId
*
* #var \Fhk\Feusersplus\Domain\Model\User
* #inject
*/
protected $cruserId;
/**
* Returns the cruserId
*
* #return \Fhk\Feusersplus\Domain\Model\User $cruserId
*/
public function getCruserId()
{
return $this->cruserId;
}
/**
* Sets the cruserId
*
* #return void
*/
public function setCruserId($cruserId)
{
$this->cruserId = $cruserId;
}
If I use cruserId.uid - it just return empty. I had specially create test ext by extension builder and make my model, tca the same, but it return empty. Help me please, good people) Do you now where is problem?
I think cruserId.uid is not your Tables fields. in TYPO3 Extabase query syntax you need to pass always feilds name like.
$query->equals($propertyName, $operand, $caseSensitive = true )
Parameters
string $propertyName The name of the property to compare against
mixed $operand The value to compare with
bool $caseSensitive Whether the equality test should be done
case-sensitive
For more infromation TYPO3 Query syntax
$query->getQuerySettings()->setRespectStoragePage(false);
$query->getQuerySettings()->setRespectSysLanguage(false);
this solved my problem
I'm currently learning extbase and fluid. I read along this SO post TYPO3 extbase & IRRE: add existing records with 'foreign_selector' to set up a relation in my extension. I got roles and people. N people can have M roles. Now everything works fine in the backend. While in the frontend I don't see the objects when I use f:debug. My problem is that the relation isn't correctly resolved by extbase (I think?).
This is my relation class:
<?php
namespace Vendor\People\Domain\Model;
/**
* Class PersonRoleRelation
* #scope prototype
* #entity
* #package Vendor\People\Domain\Model
*/
class PersonRelation extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
/**
* #var \Vendor\People\Domain\Model\Person
*/
protected $person;
/**
* #var \Vendor\People\Domain\Model\Role
*/
protected $role;
/**
* #param \Vendor\People\Domain\Model\Person $person
*/
public function setPerson($person) {
$this->person = $person;
}
/**
* #return \Vendor\People\Domain\Model\Person
*/
public function getPerson() {
return $this->person;
}
/**
* #param \Vendor\People\Domain\Model\Role $role
*/
public function setRole($role) {
$this->role = $role;
}
/**
* #return \Vendor\People\Domain\Model\Role
*/
public function getRole() {
return $this->role;
}
}
This is entity person:
<?php
namespace Vendor\People\Domain\Model;
/**
* Class Person
* #scope prototype
* #entity
* #package Vendor\People\Domain\Model
*/
class Person extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
public function __construct() {
$this->initStorageObjects();
}
/**
* #return void
*/
protected function initStorageObjects() {
$this->roles = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
/**
* Roles
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\People\Domain\Model\PersonRelation>
*/
protected $roles = NULL;
/**
* the person's first name
* #var string
* #validate StringLength(minimum = 3, maximum = 50)
*/
protected $firstname;
/**
* the person's last name
* #var string
* #validate StringLength(minimum = 3, maximum = 50)
*/
protected $lastname;
/**
* the person's responsibilities within the company
* #var string
*/
protected $role;
/**
* Photo
* #var \TYPO3\CMS\Extbase\Domain\Model\FileReference
*/
protected $photo;
/**
* detail text about the person
* #var string
* #dontvalidate
*/
protected $description;
/**
* #param string $firstname
* #return void
*/
public function setFirstname($firstname) {
$this->firstname = $firstname;
}
/**
* #return string
*/
public function getFirstname() {
return $this->firstname;
}
/**
* #param string $lastname
* #return void
*/
public function setLastname($lastname) {
$this->lastname = $lastname;
}
/**
* #return string
*/
public function getLastname() {
return $this->lastname;
}
/**
* #param string $role
* #return void
*/
public function setRole($role) {
$this->role = $role;
}
/**
* #return string
*/
public function getRole() {
return $this->role;
}
/**
* #param string $description
* #return void
*/
public function setDescription($description) {
$this->description = $description;
}
/**
* #return string
*/
public function getDescription() {
return $this->description;
}
/**
* #param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> $photo
* #return void
*/
public function setPhoto($photo) {
$this->photo = $photo;
}
/**
* #return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
*/
public function getPhoto() {
return $this->photo;
}
/**
* #return\TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\People\Domain\Model\PersonRelation>
*/
public function getRoles() {
return $this->roles;
}
}
?>
and this is role:
<?php
namespace Vendor\People\Domain\Model;
/**
* Class Role
* #scope prototype
* #entity
* #package Vendor\People\Domain\Model
*/
class Role extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
/**
* the role's title
* #var string
* #validate StringLength(minimum = 3, maximum = 50)
*/
protected $name;
public function __construct() {
}
/**
* #param string $name
* #return void
*/
public function setName($name) {
$this->name = $name;
}
/**
* #return string
*/
public function getName() {
return $this->name;
}
}
?>
ext_tables.sql:
CREATE TABLE tx_people_domain_model_person (
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
tstamp int(11) DEFAULT '0' NOT NULL,
crdate int(11) DEFAULT '0' NOT NULL,
deleted tinyint(4) DEFAULT '0' NOT NULL,
hidden tinyint(4) DEFAULT '0' NOT NULL,
firstname varchar(225) DEFAULT '' NOT NULL,
lastname varchar(225) DEFAULT '' NOT NULL,
role varchar(225) DEFAULT '' NOT NULL,
roles int(11) unsigned DEFAULT '0' NOT NULL,
description mediumtext DEFAULT '' NOT NULL,
photo mediumblob NOT NULL,
PRIMARY KEY (uid),
KEY parent (pid)
) ENGINE=InnoDB;
CREATE TABLE tx_people_domain_model_role (
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
tstamp int(11) DEFAULT '0' NOT NULL,
crdate int(11) DEFAULT '0' NOT NULL,
deleted tinyint(4) DEFAULT '0' NOT NULL,
hidden tinyint(4) DEFAULT '0' NOT NULL,
name varchar(225) DEFAULT '' NOT NULL,
PRIMARY KEY (uid)
KEY parent (pid)
) ENGINE=InnoDB;
CREATE TABLE tx_people_domain_model_person_role_rel (
uid_local int(11) unsigned DEFAULT '0' NOT NULL,
uid_foreign int(11) unsigned DEFAULT '0' NOT NULL,
sorting int(11) unsigned DEFAULT '0' NOT NULL,
KEY uid_local (uid_local),
KEY uid_foreign (uid_foreign)
) ENGINE=InnoDB;
TCA config:
tx_people_domain_model_person.php:
<?php
return array(
'ctrl' => array(
'title' => 'Person',
'label' => 'firstname',
'label_alt' => ',lastname',
'label_alt_force' => TRUE,
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'dividers2tabs' => TRUE,
'delete' => 'deleted',
'enablecolumns' => array(
'disabled' => 'hidden',
),
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('people') . 'ext_icon.gif'
),
'types' => array(
'1' => array('showitem' => 'firstname, lastname, role, description, photo, roles')
),
'columns' => array(
'hidden' => array(
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.hidden',
'config' => array(
'type' => 'check'
)
),
'firstname' => array(
'exclude' => 0,
'label' => 'Vorname',
'config' => array(
'type' => 'input',
'size' => 225,
)
),
'lastname' => array(
'exclude' => 0,
'label' => 'Nachname',
'config' => array(
'type' => 'input',
'size' => 225,
)
),
'role' => array(
'exclude' => 0,
'label' => 'Rolle',
'config' => array(
'type' => 'input',
'size' => 225,
)
),
'description' => array(
'exclude' => 0,
'label' => 'Beschreibung',
'config' => array(
'type' => 'text',
)
),
'roles' => array(
'label' => 'Rollen',
'config' => array(
'type' => 'select',
'size' => 10,
'maxitems' => 3,
'foreign_table' => 'tx_people_domain_model_role',
'MM' => 'tx_people_domain_model_person_role_rel',
// 'foreign_table' => 'tx_people_domain_model_person_role_rel',
// 'foreign_field' => 'uid_person',
// 'foreign_label' => 'uid_role',
// 'foreign_selector' => 'uid_role',
// 'foreign_unique' => 'uid_role',
// 'foreign_sortby' => 'sorting',
),
),
'photo' => array(
'exclude' => 0,
'label' => 'Foto',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('photo', array(
'appearance' => array(
'createNewRelationLinkTitle' => 'Bild hinzufügen',
'collapseAll' => FALSE,
),
'maxitems' => 1,
), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'])
),
),
);
?>
tx_domain_model_person_role_rel.php:
<?php
return array(
'ctrl' => array(
'title' => 'Relation Table',
'hideTable' => TRUE,
'sortBy' => 'sorting',
// 'tstamp' => 'tstamp',
// 'crdate' => 'crdate',
// 'dividers2tabs' => TRUE,
// 'delete' => 'deleted',
// 'enablecolumns' => array(
// 'disabled' => 'hidden',
// ),
// 'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('people') . 'ext_icon.gif'
),
'types' => array(
'0' => array('showitem' => 'uid_person, uid_role')
),
'palettes' => array(),
'columns' => array(
// 'hidden' => array(
// 'exclude' => 1,
// 'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.hidden',
// 'config' => array(
// 'type' => 'check'
// )
// ),
'uid_local' => array(
'label' => 'Person',
'config' => array(
'type' => 'select',
'MM' => 'tx_people_domain_model_person_role_rel',
'foreign_table' => 'tx_people_domain_model_person',
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
),
),
'uid_foreign' => array(
'label' => 'Rolle',
'config' => array(
'type' => 'select',
'MM' => 'tx_people_domain_model_person_role_rel',
'foreign_table' => 'tx_people_domain_model_role',
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
),
),
),
);
?>
tx_domain_model_role.php:
<?php
return array(
'ctrl' => array(
'title' => 'Rolle',
'label' => 'name',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'dividers2tabs' => TRUE,
'delete' => 'deleted',
'enablecolumns' => array(
'disabled' => 'hidden',
),
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('people') . 'ext_icon.gif'
),
'types' => array(
'1' => array('showitem' => 'name')
),
'columns' => array(
'hidden' => array(
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.hidden',
'config' => array(
'type' => 'check'
)
),
'name' => array(
'label' => 'Bezeichnung',
'config' => array(
'type' => 'input',
'size' => 225,
)
),
// 'people' => array(
// 'label' => 'Personen',
// 'config' => array(
// 'type' => 'inline',
// 'foreign_table' => 'tx_people_domain_model_person_role_rel',
// 'foreign_field' => 'uid_role',
// 'foreign_label' => 'uid_person'
// ) ,
// )
),
);
?>
ext_typoscript_setup.txt:
config.tx_extbase {
persistence {
classes {
Domain\People\Domain\Model\PersonRelation {
mapping {
tableName = tx_people_domain_model_person_role_rel
columns {
uid_local.mapOnProperty = person
uid_foreign.mapOnProperty = role
}
}
}
}
}
}
update debug output:
Domain\People\Domain\Model\Personprototypepersistent entity (uid=1, pid=18)
roles => TYPO3\CMS\Extbase\Persistence\ObjectStorageprototypeobject (3 items)
000000001bb500c600007fe33c9a2f36 => Domain\People\Domain\Model\PersonRelationprototypepersistent entity (uid=1, pid=20)
person => NULL
role => NULL
uid => 1 (integer)
_localizedUid => 1 (integer)modified
_languageUid => NULL
_versionedUid => 1 (integer)modified
pid => 20 (integer)
000000001bb5002400007fe33c9a2f36 => Domain\People\Domain\Model\PersonRelationprototypepersistent entity (uid=2, pid=20)
person => NULL
role => NULL
uid => 2 (integer)
_localizedUid => 2 (integer)modified
_languageUid => NULL
_versionedUid => 2 (integer)modified
pid => 20 (integer)
000000001bb500d100007fe33c9a2f36 => Domain\People\Domain\Model\PersonRelationprototypepersistent entity (uid=3, pid=20)
person => NULL
role => NULL
uid => 3 (integer)
_localizedUid => 3 (integer)modified
_languageUid => NULL
_versionedUid => 3 (integer)modified
pid => 20 (integer)
firstname => 'Max' (3 chars)
lastname => 'Mustermann' (10 chars)
role => 'Rolle' (5 chars)
photo => TYPO3\CMS\Extbase\Domain\Model\FileReferenceprototypepersistent entity (uid=25, pid=18)
description => 'Beschreibungstext' (17 chars)
uid => 1 (integer)
_localizedUid => 1 (integer)modified
_languageUid => NULL
_versionedUid => 1 (integer)modified
pid => 18 (integer)
So the problem is that I need to access those related objects (or the roles of a person) in the frontend.
edit: I think I'm a bit confused about the type of relation I need at all right now. 1 Person can have n roles. I don't want to relate people to roles later on anyways. I just want to create roles and later on assign roles to different people. So it would be a 1:n relation I guess. If that makes it any easier.
The solution was to add the following methods and variables in my Person class:
/**
* roles
*
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Domain\People\Domain\Model\Role>
*/
protected $roles = NULL;
/**
* __construct
*/
public function __construct() {
//Do not remove the next line: It would break the functionality
$this->initStorageObjects();
}
/**
* Initializes all ObjectStorage properties
* Do not modify this method!
* It will be rewritten on each save in the extension builder
* You may modify the constructor of this class instead
*
* #return void
*/
protected function initStorageObjects() {
$this->roles = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
/**
* Adds a Role
*
* #param \Domain\People\Domain\Model\Role $role
* #return void
*/
public function addRole(\Domain\People\Domain\Model\Role $role) {
$this->roles->attach($role);
}
/**
* Removes a Role
*
* #param \Domain\People\Domain\Model\Role $roleToRemove The Role to be removed
* #return void
*/
public function removeRole(\Domain\People\Domain\Model\Role $roleToRemove) {
$this->roles->detach($roleToRemove);
}
/**
* Returns the roles
*
* #return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Domain\People\Domain\Model\Role> $roles
*/
public function getRoles() {
return $this->roles;
}
/**
* Sets the roles
*
* #param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Domain\People\Domain\Model\Role> $roles
* #return void
*/
public function setRoles(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $roles) {
$this->roles = $roles;
}
I create a extbase Plugin in TYPO3 6.2. In one table i have a field "fuid" where i want to store the fe_users uid, to know which user can edit this record.
I set the "fuid" in createAction:
$newLocation->setFuID((int) $GLOBALS['TSFE']->fe_user->user['uid']);
This work. In the Database is the right UID.
But in the editAction:
$location->getFuID()
returns null
Why?
TCA:
fu_i_d' => array(
'exclude' => 1,
'label' => 'LLL:EXT:pitss24/Resources/Private/Language/locallang_db.xlf:tx_pitss24_domain_model_location.fu_i_d',
'config' => array(
'type' => 'select',
'items' => array (
array('',0),
),
'foreign_table' => 'fe_users',
'foreign_class' => '\TYPO3\CMS\Extbase\Domain\Model\FrontendUser',
'minitems' => 0,
'maxitems' => 1,
'size' => 10,
'appearance' => array(
'collapseAll' => 0,
'levelLinksPosition' => 'top',
'showSynchronizationLink' => 1,
'showPossibleLocalizationRecords' => 1,
'showAllLocalizationLink' => 1
),
),
),
In the Backend / TYPO3 is all OK!
In Model File.
/**
* feuseruid
*
* #var \TYPO3\CMS\Extbase\Domain\Model\FrontendUser
*/
protected $feuseruid;
// GET and SET Methods
/**
* Returns the feuseruid
*
* #return \TYPO3\CMS\Extbase\Domain\Model\FrontendUser feuseruid
*/
public function getFeuseruid() {
return $this->feuseruid;
}
/*
* Sets the feuseruid
*
* #param string $feuseruid
* #return \TYPO3\CMS\Extbase\Domain\Model\FrontendUser feuseruid
*/
public function setFeuseruid(\TYPO3\CMS\Extbase\Domain\Model\FrontendUser $feuseruid) {
$this->feuseruid = $feuseruid;
}
In TCA File
'feuseruid' => array(
'exclude' => 1,
'label' => 'Feuser Id',
'config' => array(
'type' => 'inline',
'foreign_table' => 'fe_users',
'minitems' => 0,
'maxitems' => 1,
'appearance' => array(
'collapseAll' => 0,
'levelLinksPosition' => 'top',
'showSynchronizationLink' => 1,
'showPossibleLocalizationRecords' => 1,
'showAllLocalizationLink' => 1
),
),
),
In Sql.php
feuseruid int(11) unsigned DEFAULT '0' NOT NULL,
In Controller
/**
* User Repository
*
* #var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
* #inject
*/
protected $userRepository;
$userObject = $this->userRepository->findByUid($GLOBALS['TSFE']->fe_user->user['uid']);
$orders->setFeuseruid($userObject);
$this->yourRepository->add($orders);
i found the Error! The extensionBuilder writes wrong Data in the Model:
the right values are:
Model:
/*
*
* #var TYPO3\CMS\Extbase\Domain\Model\FrontendUser
*/
protected $fuID = NULL;
...
...
...
/**
* Returns the fuID
*
* #return TYPO3\CMS\Extbase\Domain\Model\FrontendUser fuID
*/
public function getFuID() {
return $this->fuID;
}
/*
* Sets the fuID
*
* #param string $fuID
* #return TYPO3\CMS\Extbase\Domain\Model\FrontendUser fuID
*/
public function setFuID(TYPO3\CMS\Extbase\Domain\Model\FrontendUser $fuID) {
$this->fuID = $fuID;
}
Controller:
/**
* User Repository
*
* #var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
* #inject
*/
protected $userRepository;
/**
* Den aktuell angemeldeten User auslesen
*
* #return \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
*/
public function getCurrentUser() {
if ($this->currentUser == NULL && $GLOBALS['TSFE']->fe_user->user['uid'] > 0) {
$this->currentUser = $this->userRepository->findByUid($GLOBALS['TSFE']->fe_user->user['uid']);
}
return $this->currentUser;
}
Hard to say without the appropriate view of your model. It's very likely, that you have a mismatch between your model and your TCA: On the one hand you are using an integer (setFuID()), on the other hand you have an object (foreign_table/foreign_class). Maybe it's working after you have adjusted this to be the same.