TYPO3 / How to make repository from existing table fe_users?
Asked Answered
P

2

5

I am creating a special BE module with Extbase and Fluid and I need a domain object which would be representing standard FE user. When I create new domain object called e.g. Feuser and save it, the extension builder creates special repository and also wants to create special table tx_myextkey_feuser in database. But this table already exists as fe_users.

Is possible to tell typo3 that the repository for Feuser objects already exists (as fe_users table) and that typo3 should use the existing one? How can I do that?

I need it because the extension (including this BE module) needs to have every logic and controls on the same place (this BE module).

Generally speaking I need the same insert dialog for new FE users on two places if possible. If not, I can create my own New/Edit/Show actions, but I need tell TYPO3 that it should use the existing repository with FE users.

I am using typo 4.7.3.

Predetermine answered 15/8, 2013 at 13:49 Comment(0)
B
7

ExtBase already comes with a domain model for the existing table fe_user. This domain model is:

Tx_Extbase_Domain_Model_FrontendUser

It contains all default fe_users fields that come with TYPO3.

If you have extended fe_users with your own fields, you also have to extend the Tx_Extbase_Domain_Model_FrontendUser domain model and the associated repository so it knows the new fields you have added to fe_users.

The associated repository is:

Tx_Extbase_Domain_Repository_FrontendUserRepository

You have to set the storage PID(s) for the repository, so it can find your fe_users.

For controller actions used in frontend plugins use:

plugin.your_plugin {
    persistence {
        storagePid = somePid, anotherPid
    }
}

If controller actions used in backend modules use:

module.your_module {
    persistence {
        storagePid = somePid, anotherPid
    }
}

As far as I know it is not possible to use the same dialogs which come with TYPO3 for your own extension, so you have to create your own actions (new/edit/show) and forms in your backend module.

[Edit]

By default, ExtBase assumes, that all fe_users have assigned a record type. When you open one of your frontend users, you will see the tab "extended" contains a dropdown field, which is labeled "record type". If this field is not set, ExtBase will not be able to find the fe_user by using one of the find-methods from the repository.

You should set the record type for all fe_users (recommended way) or you can disable the mapping to the field by using the following TS in your setup

config.tx_extbase.persistence.classes {
    Tx_Extbase_Domain_Model_FrontendUser {
        mapping.recordType >
    }
}

For newly created fe_users or fe_groups, you can set the default value for the field "record type" by adding the following TS to your root pageTS

TCAdefaults.fe_users.tx_extbase_type = Tx_Extbase_Domain_Model_FrontendUser
TCAdefaults.fe_groups.tx_extbase_type = Tx_Extbase_Domain_Model_FrontendUserGroup
Befog answered 16/8, 2013 at 6:36 Comment(3)
Thanks for answer. I did it as you said but it is still not working. I added storagePid in typoscript but when I called method findAll of the repository, it returns zero records. In database I can see many records with the ID which is saved in module.tx_prom.persistence.storagePid. What can be wrong? I am using two repositories in one controller, both I have injected but only my first repository works. Feusers repository does not.Predetermine
If your fe_users record do not have a "record type" assigned, you have to set this field. See my updated answer how to set the field by default or how to disable the field-check.Befog
Thanks for reply. Unfortunately the extbase documentation is quite poor so answers to these type of questions must be answered somewhere else. Again, thank you.Predetermine
S
6

For Extbase 6.X

You need to give class like \TYPO3\CMS\Extbase\Domain\Model\FrontendUser instead of Tx_Extbase_Domain_Repository_FrontendUserRepository in Extend existing model class field inside extension builder

After that you can have control of fe_users inside your model....

Also add file ext_typoscript_setup.txt in root of your extension(added automatically if generated via extension_builder)

config.tx_extbase{
    persistence{
        classes{

            TYPO3\CMS\Extbase\Domain\Model\FrontendUser {
                subclasses {
                    Tx_Extendfeuser_Extended = Model_class_with_namespace
                    
                }
            }
            Vendor\EXt\Domain\Model\Extended {
                mapping {
                    tableName = fe_users
                    recordType = Tx_Extendfeuser_Extended
                }
            }
            
        }
    }
}

Thanks!!!

Works with TYPO3 7.6.X as well

Superintend answered 13/3, 2014 at 10:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.