TYPO3 Hook not found

1.8k views Asked by At

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

There are 2 answers

0
user1508609 On

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!!!

1
Claus Due On

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).