biedert
biedert

Reputation: 208

Get sys_categories from tt_content flexform settings

Let's say I have a FE Plugin with the option to set some sys_category references via the following flexform field:

                    <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>

Now I want to get all category Objects referenced in the flexform in the controller of the plugin. What's the best approach to do so? Should’nt there already be a suitable repository function somewhere? Thank you for your help!

Upvotes: 0

Views: 1147

Answers (1)

Georg Ringer
Georg Ringer

Reputation: 7939

There is no dedicated API for that, however normally you wouldn't need the mm-relation. Removing that and having it like

<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>

it is much easier to retrieve the categories. You can also take a look at the CategoryRepository I am using for the news extension https://github.com/georgringer/news/blob/master/Classes/Domain/Repository/CategoryRepository.php

Upvotes: 1

Related Questions