For coders TYPO3 Tech Corner

[PHP] Replace FlexForm of an extension

[PHP] Replace FlexForm of an extension

TYPO3 developers need new fields from time to time in the FlexForm settings of other extensions (such as news or powermail). The following snippet shows you how you can completely replace a FlexForm using the example of the extension in2studyfinder.

ext_localconf.php eurer Extension (z.B. Sitepackage):

<?php defined('TYPO3_MODE') || die(); call_user_func( function () { /** * Overwrite FlexForm with a new one */ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['postUserLookUp'][] = \Vendor\YourSitepackage\Hooks\OverwriteFlexForm::class . '->overwrite'; } );

OverwriteFlexForm.php:

<?php declare(strict_types=1); namespace Vendor\YourSitepackage\Hooks; /** * Class OverwriteFlexForm */ class OverwriteFlexForm { /** * @var string */ protected $path = 'FILE:EXT:your_sitepackage/Configuration/FlexForms/FlexformStudyfinderList.xml'; /** * @return void */ public function overwrite() { $GLOBALS['TCA']['tt_content']['columns']['pi_flexform']['config']['ds']['in2studyfinder_pi1,list'] = $this->path; } }

FlexformStudyfinderList.xml:

<T3DataStructure> <meta> <langDisable>1</langDisable> </meta> <sheets> <main> <ROOT> <TCEforms> <sheetTitle>LLL:EXT:in2studyfinder/Resources/Private/Language/locallang_db.xlf:listView</sheetTitle> </TCEforms> <type>array</type> <el> <settings.flexform.studyCourseDetailPage> <TCEforms> <exclude>1</exclude> <label>LLL:EXT:in2studyfinder/Resources/Private/Language/locallang_db.xlf:detailView</label> <config> <type>group</type> <internal_type>db</internal_type> <allowed>pages</allowed> <size>1</size> <maxitems>1</maxitems> <minitems>1</minitems> <show_thumbs>1</show_thumbs> <wizards> <suggest> <type>suggest</type> </suggest> </wizards> </config> </TCEforms> </settings.flexform.studyCourseDetailPage> <settings.flexform.select.department> <TCEforms> <label>LLL:EXT:in2studyfinder/Resources/Private/Language/locallang_db.xlf:department</label> <config> <type>select</type> <renderType>selectCheckBox</renderType> <maxitems>9999</maxitems> <size>5</size> <minitems>0</minitems> <foreign_table>tx_in2studyfinder_domain_model_department</foreign_table> <foreign_table_where>and tx_in2studyfinder_domain_model_department.sys_language_uid in (-1,0) order by tx_in2studyfinder_domain_model_department.title</foreign_table_where> </config> </TCEforms> </settings.flexform.select.department> <settings.flexform.select.graduation> <TCEforms> <label>LLL:EXT:in2studyfinder/Resources/Private/Language/locallang_db.xlf:academicDegree</label> <config> <type>select</type> <renderType>selectCheckBox</renderType> <maxitems>9999</maxitems> <size>5</size> <minitems>0</minitems> <foreign_table>tx_in2studyfinder_domain_model_graduation</foreign_table> <foreign_table_where>and tx_in2studyfinder_domain_model_graduation.sys_language_uid in (-1,0) order by tx_in2studyfinder_domain_model_graduation.title</foreign_table_where> </config> </TCEforms> </settings.flexform.select.graduation> <settings.flexform.bodytext> <TCEforms> <label>LLL:EXT:in2studyfinder_extend/Resources/Private/Language/locallang_db.xlf:flexform.bodytext</label> <config> <type>text</type> <default></default> <enableRichtext>1</enableRichtext> <richtextConfiguration>default</richtextConfiguration> </config> <defaultExtras>richtext[]:rte_transform[mode=ts_css]</defaultExtras> </TCEforms> </settings.flexform.bodytext> </el> </ROOT> </main> </sheets> </T3DataStructure>

"Code faster, look at the time" - does this sound familiar to you?

How about time and respect for code quality? Working in a team? Automated tests?

Join us

SQL: Show all tables sorted by size in descending order

Lately I've been using the SQL command more often to find out which tables in the TYPO3 database are the largest. I've published the snippet once.

Go to news

TYPO3 12 with CKEditor 5: Styles in a single selection

If you set a link in the RTE in TYPO3, you may have to choose between different link classes, for example to create buttons in the frontend. What's new in TYPO3 12 is that you can select not just one...

Go to news

Null-Safe Operator in the TYPO3 area

With the introduction of PHP8, problems with undefined arrays or variables in general can arise in many places. Here are a few examples and simple solutions.

Go to news

Delete the first/last lines of a (SQL) file

There isn't much to say about the following commands. Sometimes it can be useful to delete the first (or last) X lines from a file. And if the file is too large to open with a conventional program, a...

Go to news

b13/container: Add and modify child elements in edit view

Unlike gridelements, you cannot manage the child elements in the B13 Container extension when you open the container in the editing view. I would be happy to show you how you can quickly install this...

Go to news

Menu comparison: Numbers, numbers, numbers

Go to news