[TYPO3-mvc] How to extend a model class from within another extension?

Thomas "Thasmo" Deinhamer thasmo at gmail.com
Sun Jan 17 20:24:48 CET 2010


Hello and thanks for your answer!

As Martin already stated, if the new model is an extended
version (child class) of the original class, there should
be no problem using type hinting - and also Extbase should
take care of correct object validation of extended objects.

The big problem I see is the lack of support for extending
already existing models. The only solution I can think of by now,
would be to integrate some kind of hooks in my extension, wherever
I want to be sure the model is beeing reconstituted/created/...

That's a bit of a very big issue, imho a missing feature,
because it is already possible to extend another's extension
table and TCA, but still NOT the model.

For the meanwhile I added the new getters and setters to the
already existing extension (ExtOld) which results in the fact,
that the extension is not updateable anymore in future.

So, is it very difficult to implement this sort of extending a
model or even controllers/repositories/services? Maybe there's
already some sort of discussion or solution ongoing somewhere?!

Thank you,
Thomas


Franz Koch schrieb:
> Hi Thomas,
> 
>> For better understanding I want to get more into detail.
> ...
>> $this->productRepository =
>> t3lib_div::makeInstance('Tx_ExtOld_Domain_Repository_ProductRepository');
>>
>> And in my oppinion, this repository SHOULD return the NEW model objects
>> of which the class is defined in ExtNew (Tx_ExtNew_Domain_Model_Product),
>> which is NOT the case - it will always return the 'old' model.
>>
>> So, I'm wondering if it is possible to tell Extbase to take the new 
>> class?!
> 
> As far as I have seen from the source it's not possible - and that's a 
> big issue I think. Imagine Typo3 would run on extbase, you would not be 
> able to extend tt_content or pages in any way.
> Although it would be possible for extbase to remap the classes according 
> to some TS configuration (you would have to implement this in 
> DataMapper->createEmptyObject I think), it might still not work in any 
> way, because of all the type declarations used all over the code, f.e. 
> "function setFoo(Tx_ExtOld_Domain_Model_Foo $foo)" which will throw a 
> error if a model Tx_ExtNew_Domain_Model_Foo is passed to it. So from my 
> point of view magic getters/setters are needed or some fancy magic 
> service implementing getters/setters on the fly by rewriting classes 
> according to some TS configuration etc.
> 


More information about the TYPO3-project-typo3v4mvc mailing list