Felix
Felix

Reputation: 5619

Get list of Frontend Usergroups

I've tried to get a list with all Frontend Usergroups

I've tried this:

    /**
 * Protected Variable FrontendUserGroupRepository wird mit NULL initialisiert.
 *
 * @var \ReRe\Rere\Domain\Repository\FrontendUserGroupRepository
 * @inject
 */
protected $FrontendUserGroupRepository = NULL;

and then this

 $feUserGroups = $this->frontendUserGroupRepository->findAll();

But the list is always empty, even if there are 2 usergroups in the database.

Update ... i tried this as repository

class FrontendUserGroupRepository extends \Typo3\CMS\Extbase\Domain\Repository\FrontendUserGroupRepository {

     // Example for repository wide settings
    public function initializeObject() {
        /** @var $defaultQuerySettings Tx_Extbase_Persistence_Typo3QuerySettings */
        $defaultQuerySettings = $this->objectManager->get('Tx_Extbase_Persistence_Typo3QuerySettings');
        // go for $defaultQuerySettings = $this->createQuery()->getQuerySettings(); if you want to make use of the TS persistence.storagePid with defaultQuerySettings(), see #51529 for details

        // don't add the pid constraint
        $defaultQuerySettings->setRespectStoragePage(FALSE);
        // don't add fields from enablecolumns constraint
        $defaultQuerySettings->setRespectEnableFields(FALSE);
        // don't add sys_language_uid constraint
        $defaultQuerySettings->setRespectSysLanguage(FALSE);
        $this->setDefaultQuerySettings($defaultQuerySettings);
    }

}

but I got this error:

Could not analyse class:Typo3\CMS\Extbase\Domain\Repository\FEUserGroupsRepositry maybe not loaded or no autoloader

I've added the a new dependecy injection and reinstalled the module ...

Upvotes: 0

Views: 1523

Answers (1)

biesior
biesior

Reputation: 55798

By default each Extbase repository has flag respectStoragePage set to true, that means that user groups need to be placed at the page which is configured as Default storage PID in your exts constants, anyway as I saw you probably don't include it at all.

In such case you need to create own repository extending FrontendUserGroupRepository and then initialize it without respecting the storage.

It's described in official docs.

Edit: if you extending some model/repo in your extension Builder automatically limits your repo to objects of your type only, i.e. by adding in TS mapping:

 recordType = Tx_Rere_FrontendUserGroup

So if you want to get access to all records of extended model, just remove the recordType from ext_typoscript_setup.txt completely (don't forget to clear system cache).

Upvotes: 4

Related Questions