---
title: "Extend FlexForms"
manual: "News system"
version: "main"
permalink: "https://docs.typo3.org/permalink/georgringer/news:extendflexforms@main"
source: "Tutorials/ExtendNews/ExtendFlexforms/Index.rst"
rendered: "2026-09-23T19:24:09+00:00"
---

# Extend FlexForms {#extendflexforms}

Following fields of the plugin configuration can be extended without
overriding the complete FlexForm configuration.

-   [Selectbox "Sort by"](https://docs.typo3.org/permalink/georgringer/news:selectbox-sort-by@main)
-   [Extend FlexForms with custom fields](https://docs.typo3.org/permalink/georgringer/news:extend-flexforms-with-custom-fields@main)

## Selectbox "Sort by" {#selectbox-sort-by}

The sorting can be extended by adding the value to

```php
$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['orderByNews']
```

Default values are: tstamp,datetime,crdate,title

## Extend FlexForms with custom fields {#extend-flexforms-with-custom-fields}

If you need additional fields in the FlexForm configuration, this can be done by using a hook in the Core.

> [!IMPORTANT]
> Using such event is *not* restricted to the news extension. It can be used for any extension.
> One working example can be found in `FlexFormHook` of EXT:eventnews.

**Register the Event**

Add this to `Services.yaml` of your extension:

```yaml
services:
    Vendor\ExtKey\EventListener\ModifyFlexformEvent:
        tags:
            - name: event.listener
              identifier: 'flexParsing'
              event: TYPO3\CMS\Core\Configuration\Event\AfterFlexFormDataStructureParsedEvent
```

**Add the hook**

Create the class `ModifyFlexformEvent` in your extension in `Classes/EventListener/ModifyFlexformEvent.php` and add the path to an additional
FlexForm file.

```php
<?php

namespace Vendor\ExtKey\EventListener;

use TYPO3\CMS\Core\Configuration\Event\AfterFlexFormDataStructureParsedEvent;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class ModifyFlexformEvent
{
    public function __invoke(AfterFlexFormDataStructureParsedEvent $event): void
    {
        $dataStructure = $event->getDataStructure();
        $identifier = $event->getIdentifier();

        // $identifier['dataStructureKey'] depends on the selected plugin!
        if ($identifier['type'] === 'tca' && $identifier['tableName'] === 'tt_content' && $identifier['dataStructureKey'] === '*,news_pi1') {
            $file = GeneralUtility::getFileAbsFileName('EXT:extKey/Configuration/Example.xml');
            $content = file_get_contents($file);
            if ($content) {
                ArrayUtility::mergeRecursiveWithOverrule($dataStructure['sheets'], GeneralUtility::xml2array($content));
            }
        }

        $event->setDataStructure($dataStructure);
    }
}
```

**Create the FlexForm file**

Create the FlexForm file you just referenced in the hook. This can look like that. (Syntax for TYPO3 12 LTS+)

```html
<sheets>
    <extra>
        <ROOT>
            <sheetTitle>Fo</sheetTitle>
            <type>array</type>
            <el>
                <settings.postsPerPage>
                    <label>Max. number of posts to display per page</label>
                    <config>
                        <type>input</type>
                        <size>2</size>
                        <eval>int</eval>
                        <default>3</default>
                    </config>
                </settings.postsPerPage>
            </el>
        </ROOT>
    </extra>
</sheets>
```
