0
votes

I am currently trying to write a Hook to add extra fields to a Flexform. Therefore I followed this tutorial: https://docs.typo3.org/typo3cms/extensions/news/DeveloperManual/ExtendNews/ExtendFlexforms/Index.html?fref=gc&dti=250938618364487#extend-flexforms-with-custom-fields

But when I go to a page in the backend that contains an options from a Flexform I get the following Error: Class 'ID\SearchBarAdditional\Hooks\FlexFormHook' not found.

I register the Hook in the ext_localconf like this:

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][\TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::class]['flexParsing'][] = \ID\SearchBarAdditional\Hooks\FlexFormHook::class;

and my Hook-file is here: typo3conf/ext/search_bar_additional/Classes/Hooks and is initialized that way:

namespace ID\SearchBarAdditional\Hooks;
class FlexFormHook { /* ... */

So in my opinion everything is in the right place and should work, but I do still get the error that TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance("ID\SearchBarAdditional\Hooks\FlexFormHook") fails.

Do you guys have any ideas, what could be wrong? Do I have to register the Hook in \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin( or something similar (as the posted code is really the only thing I've done)?

2
Whenever you add new PHP classes to your extension, they need to be registered/autoloaded. Easiest way is, to deinstall/install your extensions via ExtensionManager, or using installtool 'Dump Autoload Information' in TYPO3 CMS 8jokumer
sadly this did not work :(user1508609
Reinstalling or dumping class loading is not enough if the class loading is not registered correctly to begin with, which appears to be the problem in this case.Claus Due
@user1508609 are you using composer? Do you have a file typo3conf/ext/search_bar_additional/composer.json?jokumer
no, I am not using composer.user1508609

2 Answers

3
votes

This is a typical class loading error. Check that you added your PHP namespaces to composer autoloading and/or ext_emconf.php and make sure your filenames are correctly named according to PSR-4. If in doubt you can inspect the class loading map files generated by composer in vendor/composer (if you use composer for class loading, which you definitely should do).

0
votes

I found the mistake: My Hook does indeed not get loaded. I tried to 'include' it in the ext_localconf.php and it is working now. But as this is of course an extremely ugly solution I posted a second question, how to load a hook here: Typo3 8.X - autoload Hook

Thank you for your help!!!