Developer forum

Forum » Development » Code first Item tab example

Code first Item tab example

Claus Kølbæk
Claus Kølbæk
Reply

Hey

I am looking for an example for using an item tab in the code first approach. 

I found the following:

https://doc.dynamicweb.com/api/html/770aa35e-0b4b-50ee-74b7-1a8b855939ba.htm

https://doc.dynamicweb.com/forum/cms-standard-features/cms-standard-features/code-first-item-tab-field

And it has gotten me as far as to create the item with the tabs in it, but I am getting a cast to string error when trying to actual save an item with tabs in it.

So do anyone have a working example I can get some inspiration from? :)


Replies

 
Nicolai Pedersen
Reply

And your code...?

 
Claus Kølbæk
Claus Kølbæk
Reply

Was hoping for a working example, but we can try and do it like that aswell ofc.

Here you go:

[Item("My Example Item")]
    [AreaRule,
        ModuleAttachmentRule(false),
        StructureRule(StructureContextType.Paragraphs),
        ParentRule(ParentRestrictionRule.ParentType.ItemType),

    ]
    [Category("Paragraphs")]
    [Icon(KnownIcon.CropLandscape)]
    public class MyExampleItem : ItemEntry {

        [Group("General")]
        [Name("Content")]
        [ItemTabEditor("Content", "MyContentExampleItem")]
        public ItemTabEditorAttribute Content { get; set; }      

        public override void Delete(ItemContext context) {
            base.Delete(context);
        }

        public override void Save(ItemContext context) {
            base.Save(context);
        }

    }

[
        Item("Content"),
        AreaRule,
        ModuleAttachmentRule(false),
        StructureRule(StructureContextType.ItemList),
        Category("Partials"),
        Icon(KnownIcon.FileTextO)
    ]
    public class MyContentExampleItem: ItemEntry {

        [Group("General")]
        [Name("Heading")]
        public string Heading { get; set; }


        [Group("General")]
        [Name("Text")]
        [RichText]
        public string Text { get; set; }

        public override void Delete(ItemContext context) {
            base.Delete(context);
        }

        public override void Save(ItemContext context) {
            base.Save(context);
        }

    }

 

[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
    public class ItemTabEditorAttribute : ItemTypeEditorAttribute {
        public ItemTabEditorAttribute(string name, string itemType) : base(name, itemType) {
            EditorType = typeof(ItemTypeTabEditor);
        }
        protected override void InitializeEditorConfiguration(ItemField itemField) {
            ItemTypeTabEditor itemListEditor = new ItemTypeTabEditor() { ItemType = ItemType };
            itemField.EditorConfiguration = itemListEditor.GetParametersToXml(false);
        }
    }

 
Vladimir Shushunov Dynamicweb Employee
Vladimir Shushunov
Reply
This post has been marked as an answer

Hi Claus,

it seems there is a small mistake in your example :

property Content  should have a string type: public string Content { get; set; }     

Btw try to use built-in attribute ItemTypeTabEditor - it appeared in code since DW9.6:

        [Group("General")]
        [Name("Content")]
        [ItemTypeTabEditor("Content", "MyContentExampleItem")]
        public string Content { get; set; }

Best regards,

Vladimir

Votes for this answer: 1
 
Claus Kølbæk
Claus Kølbæk
Reply

Hi Vladimir

The built-in attribute ItemTypeTabEditor was exactly what I was looking for, thank you.

Could you maybe update the documentation found at the bottom of api page (https://doc.dynamicweb.com/api/html/770aa35e-0b4b-50ee-74b7-1a8b855939ba.htm ) - just so the examples are all there for future reference? :) 

 
Claus Kølbæk
Claus Kølbæk
Reply

@Vladimir - Do you also have the code for supplying max width and height on images used as icons on fx a radio button list?

Using the RadioButtonList I can supply it positions for both labels and icons, but I cannot seem the find  the width properties nor the encode value.

 
Vladimir Shushunov Dynamicweb Employee
Vladimir Shushunov
Reply

Hi Claus,

It seems these properties are not yet supported.
I register a task to do it: #89754.

Best regard,

Vladimir 

 
Claus Kølbæk
Claus Kølbæk
Reply

Hi Vladimir

Sounds good. - Allow sorting of elements in a checkbox list also seems to be missing, so might want to add that together with the rest.

 
Claus Kølbæk
Claus Kølbæk
Reply

oh and now that I am spamming you already :) 

 

I am trying to generate a checkbox list with the values of page items. I have 2 ways of doing that currently:

[OptionItem("MyPage", "Title", "Id", SourceType = FieldOptionItemSourceType.CurrentArea)]
[OptionSql("SELECT * FROM Page Where PageItemType = 'MyPage' and PageAreaID = 1", "PageMenuText","PageID")]

The problem however is that the first option only grants me access to the itemId, therefor I much prefer option 2 where I can get the pageId right there, but here I then lack the option to limit the list to only show the elements from the CurrentArea.

Do you see a good solution to this? Else I am ofc. just going with option one for now, and then ask for the correct page via the item in the template.

 
Vladimir Shushunov Dynamicweb Employee
Vladimir Shushunov
Reply

Hi Claus,

on my opinion the first option is the most correct!

Best regards,

Vladimir

 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply

Hi Claus

The problem regarding #89754 has been implemented in Dynamicweb release 9.9.7

You are able to get this from the release section:

https://doc.dynamicweb.com/downloads/releases

Let me know if you need any more help regarding this

Kind Regards
Dynamicweb Support
Kristian Kirkholt

 

You must be logged in to post in the forum