[TYPO3-dev] Add Model to Extension by External Extension

Stephan Schuler Stephan.Schuler at netlogix.de
Tue Oct 22 20:24:35 CEST 2013


Hi Bernd.

The first, very clean way to do this relies on proper usage of the object manager as a factory. As soon as your Ext1 uses "new" for creating blog objects, this will no longer work.

In the first step, you will need to extend the Extension1\Blog. Just use "class Extension2\Domain\Model\Blog extends Extension1\Domain\Model\Blog" or something.
This Extension2\Domain\Model\Blog cann have the "author" property, as well as setters an getters.
The second thing is to create TypoScript that tells the ObjectManager to create Extension2\Domain\Model\Blog objects whenever Extension1\Domain\Model\Blog is requested. I don't have the proper syntax at hand, but there sure is.
The third thing is: Extend TCA and SQL.

Here you need to decide of you "overrule" the current blog object or create different types. The most commen way would be to create diffent types.

The TCA needs to have a type field for this, and you are required to add propper TypoScript that contains two things. The first is: The Extension1\Domain\Model\Blog has sublcasses. The second is: The Extension2\Domain\Model\Blog1 is Subclass of Extension1\Domain\Model\Blog.

Instead of telling the ObjectManager to create Extension2\Blog objects, you could extend the BlogController as well and tell the ObjectManager to create Extension2\Controller\BlogController instead of Extension1\Controller\BlogController.

But the thing is: It's not really "from the outside". You cannot, e.g., use a Extension1 which creates Blogs and BlogPosts, an Extension2 wich adds authors to BlogPosts and an Extension3 that adds comments to BlogPosts. Since this concept only works with extending the original BlogPost object and PHP doesn't know about multi inheritance, there can only be one extending mechanism be active at one time.


And here's the point where you might want to re-think the concept of Extension1 being extended. The thing I just exlained was: Adding "blogpost.author". That's possible, but it's limited to only one extension.
Another way woud be to see it just the other way around. Instead to make the BlogPost object know its authors, you could introduce authors that know their BlogPosts. This way around, you can leave the original BlogPost object completely untouched. Unless you use a certain AuthorViewHelper which utilizes the AuthorRepository in order to findOneByBlogPost, the BlogPost has no knowledge about Authors.

By the way: The fact that typo3.org uses typo.org instead of www.typo3.org really annoys me almost once a day. You cannot just use google for "extbase inheritance site:documentation.typo.org" for official documentation. You are forced to use google for "extbase inheritance site:typo.org", which returns tons of forum.typo.org and list.typo.org results that I really don't care, I just want to point to official documentation.

This is what I searched for:
> domain model inheritance typoscript site:typo3.org -site:flow.typo3.org -site:forge.typo3.org -site:forum.typo3.org -site:docs.typo3.org/flow -site:lists.typo3.org

Some clicking results me to this:
> http://docs.typo3.org/typo3cms/ExtbaseFluidBook/b-ExtbaseReference/Index.html#typoscript-configuration
See the persistence.* stuff related to mapping and subclass.

Regards,

Stephan Schuler
Web-Entwickler

Telefon: +49 (911) 539909 - 0
E-Mail: Stephan.Schuler at netlogix.de
Website: media.netlogix.de



--
netlogix GmbH & Co. KG
IT-Services | IT-Training | Media
Neuwieder Straße 10 | 90411 Nürnberg
Telefon: +49 (911) 539909 - 0 | Fax: +49 (911) 539909 - 99
E-Mail: info at netlogix.de | Internet: http://www.netlogix.de

netlogix GmbH & Co. KG ist eingetragen am Amtsgericht Nürnberg (HRA 13338)
Persönlich haftende Gesellschafterin: netlogix Verwaltungs GmbH (HRB 20634)
Umsatzsteuer-Identifikationsnummer: DE 233472254
Geschäftsführer: Stefan Buchta, Matthias Schmidt



________________________________________
Von: typo3-dev-bounces at lists.typo3.org [typo3-dev-bounces at lists.typo3.org]" im Auftrag von "Bernd Schönbach [bs.newsfeeds at googlemail.com]
Gesendet: Dienstag, 22. Oktober 2013 17:31
An: typo3-dev at lists.typo3.org
Betreff: [TYPO3-dev]  Add Model to Extension by External Extension

Hi,

is there a way to add a model to extension_1 by installing extension_2
and not having to modify extension_1?

Example:
I create a blog extension which is great with creating blog entries.

Now I want to attach authors to my blog entries, without touching the
blog extension since I don't need authors in all of my websites.
Is there a way to do this?

As far as I understood I would still need an author model within the
blog extension, although I can map the new model with the persistence
setup in the typoscript. Is that correct or does another way exist to
add this model and the relation?

Thanks
Bernd
_______________________________________________
TYPO3-dev mailing list
TYPO3-dev at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-dev


More information about the TYPO3-dev mailing list