简体   繁体   中英

TYPO3 fill backend fields in content element with database values

I'm trying to distribute JSON data from inside a tt_content database field into the other existing fields, like the TYPO3 default input field header.

I tried finding a hook which lets me handle the distribution manually like I could while saving via

$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][]

in my ext_localconf.php. I couldn't find one. So I took a look at the TCA to see if there are possible settings I can use, but I couldn't as well.

Do you know a way on how to do this data distribution manually?

I found the solution:

You have to do 2 things in your ext_localconf.php file

To change data before saving to the database you have to call:

$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = \YourNamespace\Hooks\YourClass::class;

To handle data before it's being loaded to the backend fields:

$GLOBALS ['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['tcaDatabaseRecord'][\YourNamespace\FormDataProvider\YourOtherClass::class]['depends'][0] = TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseEditRow::class;

For loading into the frontend or template you need in your setup typoscript:

tt_content {
    your_content_element_name =< lib.contentElement
    your_content_element_name {
        templateRootPaths {
            1 = EXT:your_extension_name/Resources/Private/Templates/
        }
        partialRootPaths {
            1 = EXT:your_extension_name/Resources/Private/Partials/
        }
        templateName = YourTemplateName
        dataProcessing {
            1 = YourNamespace\DataProcessing\YourClassProcessor
        }
    }
}

All those classes can be compared to the corresponding core classes.

I hope this helps someone in the future.

Kind regards!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM