1

I have in the model of my own extension a class that extends of FE user of TYPO3 7.6 call CommunityManager, I want to use the calls common to the repository like findByUid() or findAll() but they do not work, the value of return is Null.

I've been researching about it, even in several here questions but it still does not work. I currently have the following settings

In my CommunityManagerController

/**
 * communityManagerRepository
 *
 * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
 * @inject
 */
 protected $communityManagerRepository = null;

/**
 * action list
 *
 * @return void
 */
 public function listAction()
  {
    $this->communityManagerRepository = $this->objectManager->get('VENDOR\MyExt\Domain\Repository\CommunityManagerRepository');
    $communityManagers = $this->communityManagerRepository->findAll();
    $this->view->assign('communityManagers', $communityManagers);
  }

The CommunityManagerRepository

class CommunityManagerRepository extends TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
{
  public function initializeObject()
  {
    $defaultQuerySettings = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings::class);
    $defaultQuerySettings->setRespectStoragePage(false);
    $this->setDefaultQuerySettings($defaultQuerySettings);
  }
 }

And the Typoscript code

In constants

plugin.tx_myext_nameofmyplugin {
  persistence {
    storagePid = 5
  }
}

In setup

 config.tx_extbase {
  persistence {
    classes {

      TYPO3\CMS\Extbase\Domain\Model\FrontendUser {
        subclasses {
          Tx_MyExt_CommunityManager = VENDOR\MyExt\Domain\Model\CommunityManager

        }
      }
      VENDOR\MyExt\Domain\Model\CommunityManager {
        mapping {
          tableName = fe_users
          recordType = Tx_MyExt_CommunityManager
        }
      }

    }
  }
}

I would appreciate you guiding me to solve the problem

César Dueñas
  • 331
  • 4
  • 18

4 Answers4

2

first of all, you are using the inject-annotation to load a repository of type \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository, but you overriding it in your action with your VENDOR\MyExt\Domain\Repository\CommunityManagerRepository. You can simply add your own repository classname in the type-annotation of your communityManagerRepository-property. Second: Don't use the inject-annotation. Do your injections with an inject method like so:

class CommunityManagerController extends TYPO3\CMS\Extbase\Mvc\Controller\ActionController{
        /**
     * The communityManagerRepository
     *
     * @var \VENDOR\MyExt\Domain\Model\CommunityManagerRepository
     */
    protected $communityManagerRepository;

    /**
     * Inject the communityManagerRepository
     *
     * @param \VENDOR\MyExt\Domain\Model\CommunityManagerRepository $communityManagerRepository
     */
    public function injectCommunityManagerRepository(\VENDOR\MyExt\Domain\Model\CommunityManagerRepository $communityManagerRepository){
        $this->communityManagerRepository = $communityManagerRepository;
    }
}

The inject-annotation is bad to use. You can read here, why it is: https://gist.github.com/NamelessCoder/3b2e5931a6c1af19f9c3f8b46e74f837

Now you don't need the line with the objectManager, because the inject-method does this for you.

Finally, according to your configuration, the communityManagerRepository will return objects of type \VENDOR\MyExt\Domain\Model\CommunityManager, but your storagePid setting will be ignored because of the $defaultQuerySettings->setRespectStoragePage(false);. Anyway, you should be getting all the fe_users records present in the system now, unless you added a new recordType for the fe_users in the persistence settings of your model (which you don't according to your example). Then extbase will only return fe_users records of the right recordType to you.

Euli
  • 1,143
  • 9
  • 17
  • Still it doesn't work. What is the correct way for call `$this->injectCommunityManagerRepository($communityManagerRepository)`, what object should send it, because the only object, that I see, it will be the property `$communityManagerRepository`? – César Dueñas Apr 20 '17 at 23:28
  • The inject-method doesn't have to be called by you. The object manager that instantiates your controller will do so on its own. – Euli Apr 21 '17 at 12:31
2

I assume that the VENDOR and MyExt are correct in your setup and that the model CommunityManager exists.

class CommunityManager extends \TYPO3\CMS\Extbase\Domain\Model\FrontendUser {
}

class CommunityManagerRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
}

In a similar situation I had to extend the setup a bit with subclasses and recordType:

config.tx_extbase { 
        persistence {
                classes {
                        TYPO3\CMS\Extbase\Domain\Model\FrontendUser {
                                subclasses {
                                        Tx_MyExt_CommunityManager = VENDOR\MyExt\Domain\Model\CommunityManager

                                }
                        }
                        VENDOR\MyExt\Domain\Model\CommunityManager {
                                mapping {
                                        tableName = fe_users
                                        recordType = Tx_MyExt_CommunityManager
                                }
                        }

                }
        }
}

See also https://stackoverflow.com/a/22374970/7896428

Community
  • 1
  • 1
Michel
  • 156
  • 1
  • 7
  • Yes, the model `CommunityManager` extends directly of `FrontendUser`. I set the typoscript and change the extend or `CommunityManagerRepository` for extbase `Repository` but it doesn't work yet – César Dueñas Apr 20 '17 at 23:42
  • I found this Typoscript in the file ext_typoscript_setup.txt , generates by Extension Builder – César Dueñas Apr 21 '17 at 17:26
  • 1
    Just needed to modify the type field in the fe_users table and associate it with our own extension – César Dueñas Oct 01 '17 at 20:37
2

My answer might be too late for this post. But I came across same issue and after debugging extbase classes I found solution.

Your setup is fine; except 1 missing variable recordTypeColumnName (This should be field in record of fe_users table that contains value "Tx_MyExt_CommunityManager").

In my own solution I took advantage of pid column in table row. As I know id of my storage folder, which will remain constant for all my records in extension.

There is 2 ways to set value of recordTypeColumnName:

Method 1:

In TCA set type in ctrl array.

  $GLOBALS['TCA'][$tableName]['ctrl']['type'] = 'pid';

Method 2:

In TypoScript constants.txt

  PID.myStorage = 5

In TypoScript setup.txt

  plugin.tx_MyExt.persistence.storagePid = {$PID.myStorage}

  config.tx_extbase {
    persistence {
      classes {
        TYPO3\CMS\Extbase\Domain\Model\FrontendUser {
          subclasses {
            {$PID.myStorage} = VENDOR\MyExt\Domain\Model\CommunityManager
          }
          recordTypeColumnName = pid
        }

        VENDOR\MyExt\Domain\Model\CommunityManager {
          mapping {
            tableName = fe_users
            recordType = {$PID.myStorage}
          }
        }
      }
    }
  }
1

There are few points to check here:

1. Check if in fe_users with pid 5 you have users stored.

2. Check if the extension typoscript is added to template.

3. Go in install tool and press clear cache button

4. There, in Controller, you don't use the CommunityManagerRepository but FrontendUserRepository from extbase you can pass first and second step if you use the CommunityManagerRepository because there you set the respectStorage to false.

Andrei Todorut
  • 4,260
  • 2
  • 17
  • 28
  • But your repository is loaded, only the data is not returned, yes ? – Andrei Todorut Apr 21 '17 at 05:32
  • Excuse me, how could check it? the repository loaded – César Dueñas Apr 21 '17 at 10:40
  • \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->communityManagerRepository) this in Controller – Andrei Todorut Apr 21 '17 at 12:52
  • Thank you. My repository is not loaded, when I call the function that you sent me the answer is `Extbase Variable Dump: NULL` – César Dueñas Apr 21 '17 at 17:23
  • Clear cache from install tool and remove folder typo3temp/autoload. Then reload the page, after the page is loaded go in typo3temp/autoload/autoload_classmap.php and search by CommunityManagerRepository. If you can't find the class maybe the namesapce it's the problem. – Andrei Todorut Apr 22 '17 at 17:14
  • Thank you, now the repository is loaded. But the data is not return. – César Dueñas Apr 24 '17 at 14:36
  • Cool. Did you try `$this->communityManagerRepository->findAll();` and set `storagePid` with your users `sys_folder`. Normally should work if already data exists and if you have set correctly the `storagePid` or set respectStorage to false. Also you can create a empty user `entity` and `add` it with `communityManagerRepository`. If your data is not added in fe_users table there is a problem, the mapping isn't correct so you have to check `extbase` config. – Andrei Todorut Apr 24 '17 at 19:44