georgringer / news

TYPO3 Extension news
GNU General Public License v2.0
264 stars 358 forks source link

Extended flexform wont work in V12 #2239

Closed mark-kirstein closed 4 months ago

mark-kirstein commented 11 months ago

Bug Report

Current Behavior In TYPO3 11 i'm using a hook to extend news flexform for newsslider column settings. All works fine. I mirgrated the hook to an eventListener for v12 based on news documentation but the extended part doesn't appear in newsplugin settings. So i debugged and recognized that:

ArrayUtility::mergeRecursiveWithOverrule($dataStructure, GeneralUtility::xml2array($content));

doesn't combine the flexform structure correctly.

Environment

Possible Solution Using: $dataStructure['sheets']['Newsslider'] = GeneralUtility::xml2array($content); instead, all works as excepted.

Greez

Mark

specialistaweb commented 11 months ago

Hi I'm the author of newsslider - I hope Georg can suggest a solution, so I can update my extension and put again online.

The solution suggested (I have not tried it):

Possible Solution Using: $dataStructure['sheets']['Newsslider'] = GeneralUtility::xml2array($content); instead, all works as excepted.

maybe works only to extend newsslider so it is better wait for a clean solution

thank you all

Alex

georgringer commented 11 months ago

maybe that helps? https://github.com/georgringer/eventnews/blob/main/Classes/Hooks/FlexFormHook.php

mark-kirstein commented 11 months ago

@specialistaweb: I'm not using your extension newsslider. I wrote about a newsslider within my provider extension. The suggested link from Georg is from his extension eventnews and works fine. Should be the clean solution. You have to write your own EventListener or Hook for extending news flexform and so you can change it as suggested. I posted the issue for Georg, so he can change the documentation.

specialistaweb commented 11 months ago

forgive me, to be more precise: I'm the author of NEWSSTYLIST. The problem is the same, Thank to Georg (I appreciate his fast answer) the problems is solved, This is very helpful: https://github.com/georgringer/eventnews/blob/main/Classes/Hooks/FlexFormHook.php

specialistaweb commented 11 months ago

Hi Georg I tried to load two different sheets, but there is no way to put them on work.

I read yoour docs (https://docs.typo3.org/p/georgringer/news/7.3/en-us/DeveloperManual/ExtendNews/ExtendFlexforms/Index.html#:~:text=If%20you%20need%20additional%20fields,a%20hook%20in%20the%20core.&text=Create%20the%20class%20FlexFormHook%20in,to%20an%20additional%20flexform%20file.&text=Create%20the%20flexform%20file%20you%20just%20referenced%20in%20the%20hook.)

and modified the Class/Hooks/FlexFormHook.php as you can see here

 if ($identifier['type'] === 'tca' && $identifier['tableName'] === 'tt_content' && $this->isActiveOnKey($identifier['dataStructureKey'])) {
        $content = file_get_contents(<first-absolute-path>);
        if ($content) {
            $dataStructure['sheets']['extraEntryEventNews'] = GeneralUtility::xml2array($content);
        }
    }

   // set the dataStructure with new data
    $event->setDataStructure($dataStructure);

   // here read again the dataStructure
    $dataStructure = $event->getDataStructure();

    $content = file_get_contents(<second-path>);
        if ($content) {
            $dataStructure['sheets']['extraEntryEventNews'] = GeneralUtility::xml2array($content);
       }

   // **set again the dataStructure,  but... only this data can generate the sheet, the previous was ignored**
    $event->setDataStructure($dataStructure);

e made several attempts, all failed. The result is the same: only the second sheet is showed.

specialistaweb commented 11 months ago

moreover, if I try to load only the first sheet, all works fine.

I modified the code above, adapted following your suggestion, all is ok but only for one sheet

But when I use your example, as stated here: https://stackoverflow.com/questions/75766942/typo3-flexform-for-plugin-with-folders

or better, here: https://github.com/georgringer/news/blob/main/Configuration/FlexForms/flexform_tag_list.xml

TYPO3 outputs an error:

t3sheet-error

There is no way to put this flexform, filled up with your code (I used the following code to be sure).

<T3DataStructure>
    <sheets>
        <!--
            ################################
              Tab 1
            ################################
        -->
        <sDEF>
            <ROOT>
                <TCEforms>
                    <sheetTitle>TAB 1</sheetTitle>
                </TCEforms>
                <type>array</type>
                <el>
                    <!-- order -->
                    <settings.orderBy>
                        <TCEforms>
                            <label>orderBy</label>
                            <config>
                                <type>select</type>
                                <renderType>selectSingle</renderType>
                                <items>
                                    <numIndex index="0" type="array">
                                        <numIndex index="0"></numIndex>
                                        <numIndex index="1"></numIndex>
                                    </numIndex>
                                    <numIndex index="1">
                                        <numIndex index="0">tstamp</numIndex>
                                        <numIndex index="1">tstamp</numIndex>
                                    </numIndex>
                                    <numIndex index="3">
                                        <numIndex index="0">crdate</numIndex>
                                        <numIndex index="1">crdate</numIndex>
                                    </numIndex>
                                    <numIndex index="4">
                                        <numIndex index="0">title</numIndex>
                                        <numIndex index="1">title</numIndex>
                                    </numIndex>
                                </items>
                            </config>
                        </TCEforms>
                    </settings.orderBy>
                </el>
            </ROOT>
        </sDEF>
        <!--
            ################################
              Tab 2
            ################################
        -->
        <additional>
            <ROOT>
                <TCEforms>
                    <sheetTitle>Tab 2</sheetTitle>
                </TCEforms>
                <type>array</type>
                <el>
                    <settings.media.maxWidth>
                        <TCEforms>
                            <label>mediaMaxWidth</label>
                            <config>
                                <type>input</type>
                                <size>5</size>
                                <eval>num</eval>
                            </config>
                        </TCEforms>
                    </settings.media.maxWidth>
                </el>
            </ROOT>
        </additional>

        <!--
            ################################
              Tab 3
            ################################
        -->
        <template>
            <ROOT>
                <TCEforms>
                    <sheetTitle>Tab 3</sheetTitle>
                </TCEforms>
                <type>array</type>
                <el>
                    <!-- Template Layout -->
                    <settings.templateLayout>
                        <TCEforms>
                            <label>templateLayout</label>
                            <config>
                                <type>select</type>
                                <renderType>selectSingle</renderType>
                                <items>
                                    <numIndex index="0" type="array">
                                        <numIndex index="0"></numIndex>
                                        <numIndex index="1"></numIndex>
                                    </numIndex>
                                </items>
                            </config>
                        </TCEforms>
                    </settings.templateLayout>
                </el>
            </ROOT>
        </template>
    </sheets>
</T3DataStructure>

Finally, the sheets are not loaded if the code above is modified (i.e. changing the sheet names, etc.)

thank for your help

mark-kirstein commented 11 months ago

I think your flexform isn't correct and you are overwriting first sheet / tab with second one. If extending news flexform and setting sheet in the hook eventListener, you don't need the tags T3DataStructure and sheets in flexform. For each tab use an extra flexform, load it into hook and set different sheetnames for each file. Tested it in my enviroment and works fine. This is my eventListener: Bildschirmfoto vom 2023-10-31 07-57-53

And the first flexform; Bildschirmfoto vom 2023-10-31 07-58-11

and second flexform: Bildschirmfoto vom 2023-10-31 07-58-26

And the be with extended tabs: Bildschirmfoto vom 2023-10-31 07-59-53

Sorry for using images but the code formating in comments doesn't work well for me.

specialistaweb commented 11 months ago

Hi, many thanks to @mark-kirstein for helping me.

Analyzing the code I have discovered some errors here described:

if ($identifier['type'] === 'tca' && $identifier['tableName'] === 'tt_content' && $this->isActiveOnKey($identifier['dataStructureKey'])) {
        $content = file_get_contents(<first-absolute-path>);
        if ($content) {
            $dataStructure['sheets']['extraEntryEventNews'] = GeneralUtility::xml2array($content);
        }
    }

above and below I used the same array definition; for each sheet I cannot use the same name ['extraEntryEventNews'] otherwise the data will be overwritten

    $content = file_get_contents(<second-path>);
        if ($content) {
            $dataStructure['sheets']['extraEntryEventNews'] = GeneralUtility::xml2array($content);
       }

   // **set again the dataStructure,  but... only this data can generate the sheet, the previous was ignored**
    $event->setDataStructure($dataStructure);

moreover the FlexFormHook.php do not require to call twice the event, so that the best practice is to define one array entry for each sheet and call the event only one time at the end.

For each sheet it is better to use an different name based on the key of the extension, such as:

$dataStructure['sheets']['newsstylist'] = GeneralUtility::xml2array($content);

(...)

$dataStructure['sheets']['newsstylist_swiperslider'] = GeneralUtility::xml2array($content);

(...)

// set the dataStructure with new data
 $event->setDataStructure($dataStructure);

the name above should be (to be more precise) the name of the sheet, so we have a file *.xml like this;

<newsstylist>
    <ROOT>
        <sheetTitle>LLL:EXT:newsstylist/Resources/Private/Language/locallang_be.xlf:flexforms_tab.swiperslider</sheetTitle>
        <type>array</type>
        <el>

and the second starting with another name;

<newsstylist-swiperslider>
    <ROOT>
        <sheetTitle>LLL:EXT:newsstylist/Resources/Private/Language/locallang_be.xlf:flexforms_tab.swiperslider</sheetTitle>
        <type>array</type>
        <el>

obviously, as suggested by @mark-kirstein the flexform should not contain any tag not supported, such as:

<T3DataStructure>
<TCEforms>
georgringer commented 4 months ago

imo all fine, closing issue for now