Issue Bug Closed

#82847extbase model object validation does not care for overwritten classes

Michael Grundkötter 10/24/17, 12:20 updated 04/11/25, 13:55

Description

When adding features to an exisiting extension by overwriting e.g. model classes via

$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['Mittwald\Typo3Forum\Domain\Model\Forum\Post'] = array(
    'className' => 'xyz\xyz\Domain\Model\Forum\Post'
);

the ValidatorResolver / ReflectionService does obviously not take the overwritten class as base for the reflection but the original one which is given in the original controller code as annotation and class hint like here:

    /**
     * Creates a new post.
     *
     * @param Topic $topic The topic in which the new post is to be created.
     * @param Post $post The new post.
     * @param array $attachments File attachments for the post.
     *
     * @validate $post \Mittwald\Typo3Forum\Domain\Validator\Forum\PostValidator
     * @validate $attachments \Mittwald\Typo3Forum\Domain\Validator\Forum\AttachmentPlainValidator
     */

    public function createAction(Topic $topic, Post $post, array $attachments = []) {

Thus, all the @validate annotations in the new class as well as the model class validators in Classes/Domain/Validator directory are ignored. Right now, this forces the developer to also overwrite the controller classes and change the type hints to the original model class which is unnecessary work, as extbase already “knows” about the new child classes when the ObjectManager is used to instantiate the original model class.

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 5

  1. Michael Grundkötter changed Related to #78394 10/24/17, 12:21

  2. Stefan Froemken commented 04/11/25, 13:35

    Thank you for reporting this issue

    Why This Issue Occurs

    The core problem here is the use of TYPO3’s XCLASS mechanism to override Extbase domain models. While this mechanism is still officially supported, it comes with serious limitations — especially when multiple extensions attempt to override the same model.

    Problems with XCLASS

    Only One Winner

    If multiple extensions attempt to XCLASS the same domain model (e.g., \Mittwald\MmForum\Domain\Model\Forum), only one will “win”. Which one? The one loaded last based on the extension loading order.

    No Merging of Modifications

    XCLASSing fully replaces the class — there’s no merging or cooperative extension. So if Extension A and Extension B both try to XCLASS the same domain model, only one will be used, and the other silently ignored.

    Alternative: extender (Community-Supported)

    While TYPO3 core does not (yet) provide a native solution for safely and modularly extending domain models, the TYPO3 extension EXT:extender allows multiple extensions to extend the same domain model without conflicts. This approach is much safer and more maintainable than relying on XCLASS in shared environments.

    Resolution

    As this issue is ultimately caused by the known limitations of XCLASS and not by a bug in TYPO3 itself or in Extbase, we will close the issue.

  3. Michael Grundkötter commented 04/11/25, 13:47

    This issue has been reported more than 7 years ago mentioning a bug in TYPO3v7 which, at the time existed in extbase and/or the XCLASS mechanism, which were not compatible obviously. Thanks for handling this issue now, but as this is absolutely outdated, even a technical solution won’t help much 7 years later. So yes, please close it and all the old issues for outdated TYPO3 versions in the tracker.

  4. Benni Mack commented and changed status New Closed 04/11/25, 13:49

    Thanks for the feedback Michael! That is still (after all these years) very valuable!

  5. Stefan Froemken commented 04/11/25, 13:55

    Sorry. Haven’t seen, that the problem is solved with TYPO3 13.0.0:
    https://github.com/typo3/typo3/commit/874ef0dbbe979f5b8d2c3e5d8b940234c7106d34