1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Extend Generic content module

Extend Generic content module

14 posts, 1 answered
  1. Gema
    Gema avatar
    46 posts
    Registered:
    02 Oct 2009
    18 Nov 2009
    Link to this post
    Hi all,

    In my department, we are working in a solution using sitefinity cms, but we need a more powerfull generic content module, so, my question is:
    Is there any way to extend generic content module, to add new complex type metadata? or
    must we create a new module that inherits generic content?

    Thanks in advance
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    18 Nov 2009
    Link to this post
    Hi mgrp,

    Could you elaborate a bit more. What do you mean by "complex metadata" ? Generally the module is fully expendable. The same apply for Sitefinity, but it really depends on what you what to achieve.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Gema
    Gema avatar
    46 posts
    Registered:
    02 Oct 2009
    18 Nov 2009
    Link to this post
    Hi Ivan,
    for example, I would like to clasify my generic content by more than one category, so I´ve been thinking about create a tree of categories and assign multiple categories to every content item.

    Could it be posible??
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    18 Nov 2009
    Link to this post
    Hello mgrp,

    It is possible. Below are steps that you should follow.

    1. Add several additional metakeys for Generic_Content provider in project's web.config file
    2. Map external templates - ContentItemEdit and ContentitemNew. You can take a look at How to map backend template

    - ContentitemNew
    3. Add your custom control - say RadCombobox inside ContentMetaFields control declaration.
    4. Bind the RadComboBox ( or another control ) to all categories for Generic_Content provider using ContentManager object, GetCategories method.
    5. When you press save button to save the content item you need to persist selected item from the RadCombobox ( or another control/s) by using SetMetaDataMethod.
    6. Modify ContentItemEdit template in the same way, but here you need to call GetMetaData for the current IContent object when editing an item.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Gema
    Gema avatar
    46 posts
    Registered:
    02 Oct 2009
    18 Nov 2009
    Link to this post
    Hi Ivan,

    I´ll try your solution.

    Thanks for all
  6. Gema
    Gema avatar
    46 posts
    Registered:
    02 Oct 2009
    19 Nov 2009
    Link to this post
    Hi Ivan,
    your last post helped me a lot. I've added my custom control in ContentNewView, and it shows my own categories, but now, I don´t know where I have to capture save button event to set my selected categories.

    Could you, please, explain me how? or show me a sample code?

    Thanks a lot
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    19 Nov 2009
    Link to this post
    Hello mgrp,

    You do not have to work with save content button. The value should be automatically persisted.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. Gema
    Gema avatar
    46 posts
    Registered:
    02 Oct 2009
    19 Nov 2009
    Link to this post
    Hi Ivan,

    My problem is that, I´ve added my custom categories treeview. I don´t work with sitefinity categories, but my own categories. When I press save button, I want the generic content item saves more than one category. I want to save all selected items in the treeview. So I can´t bind my custom control with category metadata.

    Should I extend Content view control???

    Thanks
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    19 Nov 2009
    Link to this post
    Hello mgrp,

    When we started the discussion you were talking about metadata
    "Is there any way to extend generic content module, to add new complex type metadata?"

    You need to replace the whole backend view for the module you want to modify.  Below is a sample code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Cms.Engine.WebControls;
    using Telerik.Cms.Engine.WebControls.Admin;
    using Telerik.Web.UI;
     
    /// <summary>
    /// Summary description for ContentItemNewCustom
    /// </summary>
    public class ContentItemNewCustom : ContentItemNew<ContentItemsView>
    {
        public ContentItemNewCustom()
        {
     
        }
        public override System.Type LocalizationAssemblyInfo
        {
            get
            {
                return GetType();
            }
            set
            {
                base.LocalizationAssemblyInfo = value;
            }
        }
     
        public override System.Type AssemblyInfo
        {
            get
            {
                return GetType();
            }
            set
            {
                base.AssemblyInfo = value;
            }
        }
     
        public override string LayoutTemplatePath
        {
            get
            {
                return "RETURN YOUR TEMPLATE HERE";
            }
     
        }
     
        public override string Title
        {
            get
            {
                return "SomeTitle";
            }
            set
            {
                base.Title = value;
            }
        }
     
        protected override void SaveContent()
        {
            string selectedText = this.Tree.SelectedNode.Text;
            // HERE SAVE YOUR CUSTOM CATEGORY.
            base.SaveContent();
        }
     
        //CREATE A REFERENCE TO YOUR CONTROL
        protected virtual RadTreeView Tree
        {
            get
            {
                return base.Container.GetControl<RadTreeView>("RadTreeView1", true, Telerik.Framework.Web.TraverseMethod.BreadthFirst);
            }
        }
     
     
    }

    Then replace the view through ControlsConfig file

    <viewSettings hostType="Telerik.Cms.Engine.WebControls.Admin.ContentItemsView, Telerik.Libraries">
     
    <views>
            <remove name="ContentItemNew`1"></remove>
            <add name="ContentItemNew`1" viewType="ContentItemNewCustom, App_Code"></add>
    </views>
     
    </viewSettings>


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  10. Gema
    Gema avatar
    46 posts
    Registered:
    02 Oct 2009
    20 Nov 2009
    Link to this post

    Hi Ivan, you have saved my life. This is perfect!!!

    One more question. Can I get the content ID I´ve saving before base.SaveContent()?
    I need the content ID to save custom categories of the content I´ve saving.

     

    Thanks a lot

  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    20 Nov 2009
    Link to this post
    Hi mgrp,

    Try using the following lines

    protected override void SaveContent()
       {
           Guid itemID = Guid.Empty;
           itemID = this.DataItemId;
           string selectedText = this.Tree.SelectedNode.Text;
           // HERE SAVE YOUR CUSTOM CATEGORY.
           base.SaveContent();
       }


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  12. Gema
    Gema avatar
    46 posts
    Registered:
    02 Oct 2009
    20 Nov 2009
    Link to this post
    Hi Ivan,

    I´ve tried this.DataItemId, but when I´m creating a new item, it returns an empty guid
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    20 Nov 2009
    Link to this post
    Hello mgrp,

    In this case you need to save the content and its properties manually

    protected override void SaveContent()
    {
        IContent cnt = null;
        Guid itemID = Guid.Empty;
        itemID = this.DataItemId;
            if (itemID == Guid.Empty)
            {
                cnt = this.Manager.CreateContent("text/html");
                itemID = cnt.ID;
                // do the other logic here
            }
     
    }

    It is not possible to get the content ID before it has been created which is done in base.SaveContent();

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  14. Gema
    Gema avatar
    46 posts
    Registered:
    02 Oct 2009
    21 Nov 2009
    Link to this post
    Hello Ivan,
    I´m only writing, to tell you, it works perfect.

    Thanks for your support,
    Sincerely yours,
    Gema
Register for webinar
14 posts, 1 answered