从tt_content flexform设置中获取sys_categories

时间:2018-02-05 16:06:40

标签: typo3 extbase typo3-8.x

假设我有一个FE插件,可以选择通过以下flexform字段设置一些sys_category引用:

                    <settings.categories>
                    <TCEforms>
                        <label>Some Label</label>
                        <config>
                            <type>select</type>
                            <foreign_table>sys_category</foreign_table>
                            <foreign_table_where> AND sys_category.sys_language_uid IN (-1, 0) ORDER BY sys_category.sorting ASC</foreign_table_where>
                            <MM>sys_category_record_mm</MM>
                            <MM_opposite_field>items</MM_opposite_field>
                            <MM_match_fields>
                                <tablenames>tt_content</tablenames>
                                <fieldname>categories</fieldname>
                            </MM_match_fields>
                            <maxitems>9999</maxitems>
                            <renderMode>tree</renderMode>
                            <size>10</size>
                            <treeConfig>
                                <appearance>
                                    <expandAll>1</expandAll>
                                    <showHeader>1</showHeader>
                                </appearance>
                                <parentField>parent</parentField>
                            </treeConfig>
                        </config>
                    </TCEforms>
                </settings.categories>

现在我想获得插件控制器中flexform中引用的所有类别对象。这样做的最佳方法是什么?难道不存在某个合适的存储库功能吗?谢谢你的帮助!

1 个答案:

答案 0 :(得分:1)

没有专门的API,但通常你不需要mm-relation。删除它并使其像

一样
<settings.categories>
                        <TCEforms>
                            <label>LLL:EXT:news/Resources/Private/Language/locallang_be.xlf:flexforms_general.categories</label>
                            <config>
                                <type>select</type>
                                <renderMode>tree</renderMode>
                                <renderType>selectTree</renderType>
                                <treeConfig>
                                    <dataProvider>GeorgRinger\News\TreeProvider\DatabaseTreeDataProvider</dataProvider>
                                    <parentField>parent</parentField>
                                    <appearance>
                                        <maxLevels>99</maxLevels>
                                        <expandAll>TRUE</expandAll>
                                        <showHeader>TRUE</showHeader>
                                        <width>600</width>
                                    </appearance>
                                </treeConfig>
                                <foreign_table>sys_category</foreign_table>
                                <foreign_table_where>AND (sys_category.sys_language_uid = 0 OR sys_category.l10n_parent = 0) ORDER BY sys_category.sorting</foreign_table_where>
                                <size>15</size>
                                <minitems>0</minitems>
                                <maxitems>99</maxitems>
                            </config>
                        </TCEforms>
                    </settings.categories>

检索类别要容易得多。您还可以查看我用于新闻扩展程序this answer

CategoryRepository