Project

General

Profile

Actions

Bug #83386

closed

Extbase FrontendUser Class creates ObjectStorage for Usergroups only in constructor

Added by Christopher Schnell almost 7 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Extbase
Start date:
2017-12-19
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
8
PHP Version:
Tags:
Complexity:
no-brainer
Is Regression:
No
Sprint Focus:

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();
}

Actions #1

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());

Actions #2

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.)

Actions #3

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.

Actions #4

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

Actions #5

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

Actions #6

Updated by Benni Mack over 4 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #7

Updated by Benni Mack almost 4 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF