Using the ContentTypeService I create a hierarchy of new content types like shown in the picture:
Let's say, that the TeaserBase contains a property "bodyText" and the TeaserMitBild adds a Property "picture" to it's properties. All teaser types below TeaserMitBild don't have own properties, but use the inherited properties. They will be rendered in a different way.
After creation of the property type tree all looks perfect in the Settings / Document Types view.
EDIT: The "Generic properties" tab usually shows a message saying "Master Content Type enabled This Content Type uses Master as a Master Content Type. Properties from Master Content Types are not shown and can only be edited on the Master Content Type itself".
The created DocumentTypes are missing this message.
Also if I create a document based on the inner teaser types like "Teaser 2/3" the document doesn't show any property data editor. If the property type has own properties defined, they show up in their respective tabs. My code to create the Document Types is as follows:
Thanks, but this will make the contenttypes nested (that was already working for us), but not setup the master content type structure.
You can easily check, because the Generic Properties tab will tell you:
"Master Content Type enabled This Content Type uses Master as a Master Content Type. Properties from Master Content Types are not shown and can only be edited on the Master Content Type itself"
Well there is a subtle but not very obvious difference between passing in a ContentType or an integer Id when creating a new ContentType.
When you do var contentType = new ContentType(myParentType) then the parent ContentType will be added both as a Parent and as a Master ContentType. But if you do var contentType = new ContentType(1234) the ContentType with Id 1234 will only be added as a Parent and NOT a master.
So having both ct = new ContentType(parent); and ct.AddContentType(parent); should be redundant as the second line in @mmaty's example is done within the constructor of ContentType. However, if you are creating a new ContentType and passing in the id of another ContnetType then yes, you would need to call AddContentType to have it added as a Master.
@morten: I thought, that things work like you describe it, but it wasn't the case. I tried with U 7.0.2 and it didn't work before I added the AddContentType call.
IContentType: How to set the Master Content Type?
Umbraco: 6.0.3
ASP.NET 4.0
Windows 7 / IIS 7.5
Using the ContentTypeService I create a hierarchy of new content types like shown in the picture:
Let's say, that the TeaserBase contains a property "bodyText" and the TeaserMitBild adds a Property "picture" to it's properties. All teaser types below TeaserMitBild don't have own properties, but use the inherited properties. They will be rendered in a different way.
After creation of the property type tree all looks perfect in the Settings / Document Types view.
EDIT: The "Generic properties" tab usually shows a message saying "Master Content Type enabled
This Content Type uses Master as a Master Content Type. Properties from Master Content Types are not shown and can only be edited on the Master Content Type itself".
The created DocumentTypes are missing this message.
Also if I create a document based on the inner teaser types like "Teaser 2/3" the document doesn't show any property data editor. If the property type has own properties defined, they show up in their respective tabs. My code to create the Document Types is as follows:
I'm sure I'm missing something. Could anybody tell me, what the mistake is?
Cheers
Mirko
Hi all,
I found a solution for the issue, but I think there must be a cleaner way to do it. I just add these lines in CreateDt just before returning the dt:
if ( parent != null )
{
umbraco.cms.businesslogic.web.DocumentType ct = new umbraco.cms.businesslogic.web.DocumentType( dt.Id );
ct.MasterContentType = parent.Id;
ct.Save();
}
Is there any way to setting the master document type with the new API?
Cheers
Mirko
Out of interest why are you creating DocTypes via the API?
In the new API you create the nested/inherited doc types by passing in the Parent. If when creating TeaserTab you pass it the TeaserBase ContentType.
Pseudo code:
var teaserTab = new ContentType(teaserBase);
Here is a more complete example (and you can find more in the test project of Umbraco https://github.com/umbraco/Umbraco-CMS/blob/7.1.2/src/Umbraco.Tests/TestHelpers/Entities/MockedContentTypes.cs ):
Hope this helps,
Morten
Morten,
Thanks, but this will make the contenttypes nested (that was already working for us), but not setup the master content type structure.
You can easily check, because the Generic Properties tab will tell you:
"Master Content Type enabled
This Content Type uses Master as a Master Content Type. Properties from Master Content Types are not shown and can only be edited on the Master Content Type itself"
if it would work :)
Sorry for not posting the solution. It's as simple as that:
Mmaty,
Thank you! Sometimes these things are very easy, but you 'just have to know'.
It's a friday so I can overlook thing right? ;) :P
Best,
Arnold
Well there is a subtle but not very obvious difference between passing in a ContentType or an integer Id when creating a new ContentType.
When you do
var contentType = new ContentType(myParentType)
then the parent ContentType will be added both as a Parent and as a Master ContentType. But if you dovar contentType = new ContentType(1234)
the ContentType with Id 1234 will only be added as a Parent and NOT a master.So having both
ct = new ContentType(parent);
andct.AddContentType(parent);
should be redundant as the second line in @mmaty's example is done within the constructor of ContentType. However, if you are creating a new ContentType and passing in the id of another ContnetType then yes, you would need to call AddContentType to have it added as a Master.Reference: https://github.com/umbraco/Umbraco-CMS/blob/7.1.2/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs#L26
Hope this wasn't too confusing :-/
Morten
The word "obvious" was made for other situations... I had to have a look into the Umbraco sources. The document type import shows the right code.
Oops, we had some crossposting here.
@morten: I thought, that things work like you describe it, but it wasn't the case. I tried with U 7.0.2 and it didn't work before I added the AddContentType call.
is working on a reply...