Question

I have an extension where I need to get all frontend users. I tried this:

    /**
     * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository $feUserRepository
     */
    $feUserRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( 'TYPO3\\CMS\\Extbase\\Domain\\Repository\\FrontendUserRepository' );
    $allUsers = $feUserRepository->findAll();
    $user = $feUserRepository->findByUid( 1 );

findByUid(1) works, but findAll() returns an empty object. What am I doing wrong here?

UPDATE:

It's about a news extension. I have a mm relation between tx_xxnews_domain_model_news and fe_users, so I can keep track on which users accessed which news.

TCA for News:

'columns' => array(
        ...

        'fe_users' => array(
            'exclude' => 0,
            'label' => 'LLL:EXT:xx_news/Resources/Private/Language/locallang_db.xlf:tx_xxnews_domain_model_news.fe_users',
            'config' => array(
                'type' => 'select',
                'foreign_table' => 'fe_users',
                'MM' => 'tx_xxnews_news_feuser_mm',
                'size' => 10,
                'autoSizeMax' => 30,
                'maxitems' => 9999,
                'multiple' => 0,
            ),
        ),
        ...
),

I have to show the users who accessed the news separately from the ones who did not, so I have 2 more columns which show content from a user defined function:

'reading_users' => array (
    'exclude' => 0,
    'label' => 'LLL:EXT:xx_news/Resources/Private/Language/locallang_db.xlf:tx_xxnews_domain_model_news.user_info',
    'config' => array (
        'type' => 'user',
        'size' => '30',
        'userFunc' => 'EXT:xx_news/Classes/TCA/class.tx_xxnews_tca.php:tx_examples_tca->readersInfo',
        'parameters' => array(
            'read' => TRUE
        )
    )
),
'not_reading_users' => array (
    'exclude' => 0,
    'label' => 'LLL:EXT:xx_news/Resources/Private/Language/locallang_db.xlf:tx_xxnews_domain_model_news.user_info',
    'config' => array (
        'type' => 'user',
        'size' => '30',
        'userFunc' => 'EXT:xx_news/Classes/TCA/class.tx_xxnews_tca.php:tx_examples_tca->readersInfo',
        'parameters' => array(
            'read' => FALSE
        )
    )
),

class.tx_xxnews_tca.php:

class tx_examples_tca {

    /**
     * @var \Vendor\XxNews\Domain\Repository\NewsRepository $newsRepository
     */
    protected $newsRepository;

    /**
     * Class constructor
     */
    public function __construct() {
        $this->newsRepository = new \Vendor\XxNews\Domain\Repository\NewsRepository;
    }

    public function readersInfo($params) {

        /**
         * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository $feUserRepository
         */
        $feUserRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( 'TYPO3\\CMS\\Extbase\\Domain\\Repository\\FrontendUserRepository' );
        $allUsers = $feUserRepository->findAll();
        $user = $feUserRepository->findByUid( 1 );

        var_dump( $allUsers ); //EMPTY
        var_dump( $user );     //OK
    }
}

Thank you.

Was it helpful?

Solution

The problem is that when Extbase was introduced by TYPO3, a "record type" for Frontend users was integrated. (This was just done as an example and will be removed in 6.2 BTW).

You must either set the record type of each Frontend User to the record type of your extension (it is defined in the ext_tables.php of your extension) or you can remove (clear) the necessity of the record type

config.tx_extbase.persistence.classes.Vendor/MyExtension/Domain/Model/User.mapping.recordType =

EDIT: By the way, you should inject your repository instead of using makeInstance:

/**
 * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
 * @inject
 */
protected $feUserRepository;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top