#106223custom dataprocessor can't use dependency injection
Description
I got this bug in TYPO3 11. But the same code-line occur in the current main-branch of TYPO3. https://github.com/TYPO3/typo3/blob/main/typo3/sysext/frontend/Classes/ContentObject/ContentDataProcessor.php. I wrote this ticket because of this and marked it for the current version.
I tried to build a custom dataprocessor. The dataprocessor included a dependency injection for an simple repository class. I got the exception while testing that stuff. See screenshot.
If I use the method “GeneralUtiliy::makeInstance()” in the dataprozessor, everything will work fine; teh missing dependency injection will only hinder the development of unittests.
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
Files 1
History 4
-
Garvin Hicking commented and changed status
NewNeeds Feedback <span data-processor="relativetime" data-value="2025-02-21T07:43:57+00:00" > 02/21/25, 07:43 </span> -
Dieter Dr. Porth commented <span data-processor="relativetime" data-value="2025-02-21T08:04:36+00:00" > 02/21/25, 08:04 </span>
Hi,
thanks for the fast response.
No. I have not read the remarks after the headline “Register an alias for the data processor (optional)”. I ignored it, because of ‘optional’. I installed the custom dataprocessor without an alias and the related stuff. My definition looks simply so:
@
dataProcessing.1739792316 = Vendor\MyExtension\DataProcessing\FirstCustomCategoryProcessor
dataProcessing.1739792316 {
as = mycategory
}
@ -
Chris Müller commented <span data-processor="relativetime" data-value="2025-02-21T09:04:43+00:00" > 02/21/25, 09:04 </span>
So, either you define the data processor as public (like for hooks, etc) or you define an alias. Either way, you can then use DI.
-
Garvin Hicking commented and changed category status
Needs FeedbackClosed <span data-processor="relativetime" data-value="2025-02-21T11:33:13+00:00" > 02/21/25, 11:33 </span>I agree with what Chris additionally said. You can use Dependency Injection once taking care of its requirements (tagged or shared service declaration). https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/DependencyInjection/Index.html has more background on this.
I am closing this issue due to this.
Hi!
Did you follow the advice on https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/ContentElements/CustomDataProcessing.html with the note about Dependency Injection?
Regards,
Garvin