Bug #83386
closedExtbase FrontendUser Class creates ObjectStorage for Usergroups only in constructor
100%
Description
The FrontendUser Class creates ObjectStorage for Usergroups only in the constructor, like this.
public function __construct($username = '', $password = '') { $this->username = $username; $this->password = $password; $this->usergroup = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); }
If no usergroup for the user is added upon creation of the frontenduser, it is not possible to simply add a new usergroup later. The reason is that $this->usergroup is null when fetching the frontenduser from the repository. I think this could be resolved with simply implementing an initializeObject() method in TYPO3\CMS\Extbase\Domain\Model\FrontendUser like this:
public function __construct($username = '', $password = '') { $this->username = $username; $this->password = $password; $this->initializeObject(); } public function initializeObject() { $this->usergroup = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); }
Updated by Steffen Kamper almost 7 years ago
I agree that this is not the best style, but surely you can add a usergroup later, as there is the method
$user->setUsergroup(new \TYPO3\CMS\Extbase\Persistence\ObjectStorage());
Updated by Christopher Schnell almost 7 years ago
Thanks for your reply,
of course, that's what we did:
... $feUser = $feUserRepo->findByUid($uid); if(!$feUser->getUsergroup()){ $feUser->setUsergroup(new \TYPO3\CMS\Extbase\Persistence\ObjectStorage()); } $feUser->addUsergroup($userGroup);
But it really seems to be a dirty workaround since extbase provides the solution with the initializeObject() method (maybe even the initStorageObjects() method provided by any model created by the Extension Builder might work, although I am not sure about that.)
Updated by Alexander Schnitzler almost 5 years ago
- Status changed from New to Accepted
- Target version set to Candidate for Major Version
- Complexity set to no-brainer
- Is Regression set to No
True, the initialization must take place in the initializeObject
method. That didn't change yet.
Updated by Gerrit Code Review over 4 years ago
- Status changed from Accepted to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/65177
Updated by Gerrit Code Review over 4 years ago
Patch set 1 for branch 10.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/65167
Updated by Benni Mack over 4 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 48b84741b7efa89c9fc6bb6632f35293d36ed7d8.