TYPO3 8.X - autoload Hook

793 views Asked by At

How can I autoload a hook in TYPO3?

I register it in the ext_localconf.php, but it does not get autoloaded (unless I 'include' it in the same file which is of course an extremely ugly solution). I looked into other extensions but I don't find, where the require there hooks. Shouldn't it be autoloaded in the ext_emconf?

'autoload' => [
    'psr-4' => [
        'ID\\IndexedSearchAutocomplete\\' => 'Classes'
    ],
],

But when don't use my ugly solution I get the error, that GeneralUtility::makeInstance can't find my file.

2

There are 2 answers

0
helhum On

Does this help? http://insight.helhum.io/post/130876393595/how-to-configure-class-loading-for-extensions-in

This article describes the options you have regarding class loading.

You may want to check whether your class fulfills the psr-4 standard: http://www.php-fig.org/psr/psr-4/

1
Daniel On

I assume that you are using composer in your project. Composer does the whole autoloading of classes. It "knows" all classes of extensions that were required by composer (listed in the require part of your composer.json).

Of course you can add extensions to your project without requiering them with composer. I guess, that is what you did here. In that case you have to tell composer about the classes in your composer.json.

Add a autoload section:

"autoload": {
    "psr-4": {
        "ID\\IndexedSearchAutocomplete\\": "web/typo3conf/ext/indexed_search_autocomplete/Classes"
    }
}

Of course your FQCN have to match the path above your Classes folder (that is what psr-4 means).

After that you can type composer dump-autoload and your class should be loaded.