Developer forum

Forum » CMS - Standard features » Looking for a complete ItemType code-first sample

Looking for a complete ItemType code-first sample

Peter Leleulya
Reply

Hi guys,

In my previous project I used code-first item types.
It took some try-and-error to get a working itementry class, mostly because I couldn't find proper samples.
I didn't get to use all properties which are available when you create an item type using the CMS.

I'm looking for sample code of code-first item types in the most comprehensive version, so I can take what I need.

For example a simple news item itemtype with these specs:

Models/ViewModels/NewsItem


Name:               Nieuwsbericht
SystemName:         NewsItem
Description:        Dit genereert een nieuwsbericht
Item activated for: Pages
Icon:               text_code_colored.png
Icon miniturized:   TextCode.png    
URL generation:     true
Item cache:         true
Category:           Content
Title Field:        Title    


Type           SystemName        Group            Label            Required    Options            Default value            
------------------------------------------------------------------------------------------------------------------------------------------------------------
Int            NewsItemId        MappingFields    ID               true                            Auto number            
Select         NewsCategoryId    MappingFields    Categorie        true        * from categories   First category            
(Multi)Select  RegionId          MappingFields    Regio            true        * from regions      "Niet regio specifiek"        

String         Title             StandardFields   Titel            true                                    
String         SubTitle          StandardFields   Sub titel        false                                    
LongText       Text              StandardFields   Tekst            true                                    
DateTime       NewsDate          StandardFields   Nieuwsdatum      false                                    
(Fixed)Radio   NewsType          StandardFields   Type             true        News;Featured;Add    News                
File           Image             StandardFields   Afbeelding       false                                    
Link           LandingPage       StandardFields   Link naar        false                                    
        
LongText       Tags              Tagging          Tags             false   


I would have this class file:

namespace MyApplication.Models.ViewModels
{

    // NAME
    [Name("Nieuwsbericht")]

    // SYSTEM NAME = CLASSNAME

    // DESCRIPTION
    // can not find a sample how to implement this

    // ITEM ACTIVATED FOR
    // can not find a sample how to implement this

    // ICONS
    // can not find a sample how to implement this

    // URL GENERATION (true/false)
    // can not find a sample how to implement this

    // ITEM CACHE (true/false)
    // can not find a sample how to implement this

    // ITEM TYPE CATEGORY
    [Category("Content")]

    // FIELD USED FOR TITLE
    // can not find a sample how to implement this

    public class NewsItem : ItemEntry
    {

        // MAPPING FIELDS

            // NEWS ITEM ID
            [Group("MappingFields")]
            [Name("ID")]
            [Required]
            public int NewsItemId { get; set; }

            // NEWS CATEGORY ID
            [Group("MappingFields")]
            [Name("Categorie")]
            [Required]
            // can not find a sample how to make a select box with queryable content and a default or selected value

            // REGION ID
            [Group("MappingFields")]
            [Name("Regio")]
            [Required]
            // can not find a sample how to make a multi select list with queryable content and a default selected value or selected value(s)

 

        // STANDARD FIELDS

            // TITLE
            [Group("StandardFields")]
            [Name("Titel")]
            [Required]
            public string Title { get; set; }

            // SUB TITLE
            [Group("StandardFields")]
            [Name("Subtitel")]
            public string SubTitle { get; set; }

            // TEXT
            [Group("StandardFields")]
            [Name("Tekst")]
            [Required]
            [LongText]
            public string Text { get; set; }

            // NEWS DATE
            [Group("StandardFields")]
            [Name("Nieuwsdatum")]
            public DateTime NewsDate { get; set; }

            // TYPE
            [Group("StandardFields")]
            [Name("Ype")]
            [Required]
            // can not find a sample how to make a radio button list with static content and a default or selected value

            // IMAGE
            [Group("StandardFields")]
            [Name("Afbeelding")]
            [File]
            public string Image { get; set; }

            // LINK
            [Group("StandardFields")]
            [Name("Link naar landingpage")]
            [Link]
            public string LandingPage { get; set; }

       // TAGGING FIELDS

            // TAGS
            [Group("Taggin")]
            [Name("Tags")]
            [LongText]
            public string Tags { get; set; }

    }
}


Replies

 
Lars Larsen
Reply

Hi Peter

I know of some of the annotations that you ask about:

// DESCRIPTION
?

// ITEM ACTIVATED FOR
[StructureRule(StructureContextType.Pages, StructureContextType.ItemList)]

// ICONS
[Icon("/Admin/Images/Ribbon/Icons/Small/calendar.png", "/Admin/Images/Ribbon/Icons/calendar.png")]

// URL GENERATION (true/false)
[CustomizedURLs]

// ITEM CACHE (true/false)
?

// FIELD USED FOR TITLE
[TitleField("Name")]

 

// NEWS CATEGORY ID
[Group("MappingFields")]
[Name("Categorie")]
[Required]
[OptionItem("Categorie", "Name", "Id", SourceType = FieldOptionItemSourceType.CurrentArea)]

// REGION ID
[Field("Region", typeof(CheckboxListEditor<>))]
[Group("MappingFields")]
[Name("Region")]
[Required]
[OptionItem("Region", "Name", "Id", SourceType = FieldOptionItemSourceType.CurrentArea)]

// default selected value or selected value(s): you can set default values in the constructor of the item type class

 
Peter Leleulya
Reply

Hi Lars,

Thanks for your response!
I can use this ...

I still really would like a full example from Dynamicweb though ....
They only refer to this page: http://doc.dynamicweb-cms.com/Default.aspx?ID=8258#article=4e84080a-6041-e9f4-1f8d-e77869bbb1b7

 
Lars Larsen
Reply

Hi Peter

Yeah the documentation could be better if there where some examples. But you can also see all available annotations here: http://doc.dynamicweb-cms.com/api/html/e51c1341-9de4-3947-14c3-d49b8dd1f518.htm 

 
Nicolai Høeg Pedersen
Reply

Hi Peter and Lars

Thank you for you input on this.

I've added a task for 8.9 release track (end september) to create a more complete example of code first items and how to use the item repository.

BR Nicolai

 
Peter Leleulya
Reply

Superb! yes

 
Lars Larsen
Reply

Excellent smiley

 

You must be logged in to post in the forum