TYPO3 / How to make repository from existing table

2019-01-25 19:40发布

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.

2条回答
你好瞎i
2楼-- · 2019-01-25 20:09

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
查看更多
贼婆χ
3楼-- · 2019-01-25 20:22

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

                }
            }
            SkiBoutique\SbChalets\Domain\Model\Extended {
                mapping {
                    tableName = fe_users
                    recordType = Tx_Extendfeuser_Extended
                }
            }

        }
    }
}

Thanks!!!

Works with TYPO3 7.6.X as well

查看更多
登录 后发表回答